EMAN::ScaleTransformProcessor Class Reference

Scale the image with control over the output dimensions. More...

#include <processor.h>

Inheritance diagram for EMAN::ScaleTransformProcessor:

Inheritance graph
[legend]
Collaboration diagram for EMAN::ScaleTransformProcessor:

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual string get_name () const
 Get the processor's name.
virtual void process_inplace (EMData *image)
 
Exceptions:
ImageDimensionException if the image is not 2D or 3D
InvalidParameterException if the Transform parameter is not specified

virtual EMDataprocess (const EMData *const image)
 
Exceptions:
ImageDimensionException if the image is not 2D or 3D
InvalidParameterException if the Transform parameter is not specified

virtual TypeDict get_param_types () const
 Get processor parameter information in a dictionary.
virtual string get_desc () const
 Get the descrition of this specific processor.

Static Public Member Functions

static ProcessorNEW ()

Static Public Attributes

static const string NAME = "xform.scale"

Detailed Description

Scale the image with control over the output dimensions.

Author:
David Woolford
Date:
June 2009
Parameters:
scale The amount by which to scale
cip The length of each output dimension. Non sophisticated, output dimensions can't be different

Definition at line 1582 of file processor.h.


Member Function Documentation

virtual string EMAN::ScaleTransformProcessor::get_desc (  )  const [inline, virtual]

Get the descrition of this specific processor.

This function must be overwritten by a subclass.

Returns:
The description of this processor.

Implements EMAN::Processor.

Definition at line 1616 of file processor.h.

01617                                 {
01618                                         return "The image is scaled with the clip variable in mind, being sure to preserve as much pixel information as possible.";
01619                                 }

virtual string EMAN::ScaleTransformProcessor::get_name (  )  const [inline, virtual]

Get the processor's name.

Each processor is identified by a unique name.

Returns:
The processor's name.

Implements EMAN::Processor.

Definition at line 1585 of file processor.h.

References NAME.

01586                                 {
01587                                         return NAME;
01588                                 }

virtual TypeDict EMAN::ScaleTransformProcessor::get_param_types (  )  const [inline, virtual]

Get processor parameter information in a dictionary.

Each parameter has one record in the dictionary. Each record contains its name, data-type, and description.

Returns:
A dictionary containing the parameter info.

Reimplemented from EMAN::Processor.

Definition at line 1606 of file processor.h.

References EMAN::EMObject::FLOAT, EMAN::EMObject::INT, and EMAN::TypeDict::put().

01607                                 {
01608                                         TypeDict d;
01609                                         d.put("scale", EMObject::FLOAT, "The amount by which to scale" );
01610                                         d.put("clip", EMObject::INT, "The length of each output dimension. Non sophisticated, output dimensions can't be different" );
01613                                         return d;
01614                                 }

static Processor* EMAN::ScaleTransformProcessor::NEW (  )  [inline, static]

Definition at line 1589 of file processor.h.

01590                                 {
01591                                         return new ScaleTransformProcessor();
01592                                 }

EMData * ScaleTransformProcessor::process ( const EMData *const   image  )  [virtual]

Exceptions:
ImageDimensionException if the image is not 2D or 3D
InvalidParameterException if the Transform parameter is not specified

Reimplemented from EMAN::Processor.

Definition at line 8572 of file processor.cpp.

References EMAN::EMData::clip_inplace(), EMAN::EMData::copy(), EMAN::EMData::get_clip(), EMAN::EMData::get_ndim(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Dict::has_key(), ImageDimensionException, InvalidParameterException, EMAN::Processor::params, EMAN::EMData::process(), EMAN::EMData::process_inplace(), EMAN::Dict::set_default(), t, and UnexpectedBehaviorException.

08572                                                                   {
08573         int ndim = image->get_ndim();
08574         if (ndim != 2 && ndim != 3) throw UnexpectedBehaviorException("The Scale Transform processors only works for 2D and 3D images");
08575 
08576         if ( image->get_xsize() != image->get_ysize()) {
08577                 throw ImageDimensionException("x size and y size of image do not match. This processor only works for uniformly sized data");
08578         }
08579         if ( ndim == 3 ) {
08580                 if ( image->get_xsize() != image->get_zsize()) {
08581                 throw ImageDimensionException("x size and z size of image do not match. This processor only works for uniformly sized data");
08582                 }
08583         }
08584 
08585         float scale = params.set_default("scale",0.0f);
08586         if (scale <= 0.0f) throw InvalidParameterException("The scale parameter must be greater than 0");
08587 
08588         int clip = 0;
08589 
08590         if(params.has_key("clip"))
08591         {
08592                 clip = params["clip"];
08593                 if (clip < 0) throw InvalidParameterException("The clip parameter must be greater than 0"); // If it's zero it's not used
08594         }
08595         else
08596         {
08597                 clip = (int)(scale*image->get_xsize());
08598         }
08599 
08600         Region r;
08601         if (ndim == 3) {
08602                  r = Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2,clip, clip,clip);
08603         } else { // ndim == 2 guaranteed by check at beginning of function
08604                  r = Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, clip, clip);
08605         }
08606 
08607         EMData* ret = 0;
08608         if (scale > 1) {
08609                 if ( clip != 0) {
08610                         ret = image->get_clip(r);
08611                 }
08612                 Transform t;
08613                 t.set_scale(scale);
08614                 if (ret != 0) {
08615                         ret->process_inplace("xform",Dict("transform",&t));
08616                 } else {
08617                         ret = image->process("xform",Dict("transform",&t));
08618                 }
08619         } else if (scale < 1) {
08620                 Transform t;
08621                 t.set_scale(scale);
08622                 ret = image->process("xform",Dict("transform",&t));
08623                 if ( clip != 0) {
08624                         ret->clip_inplace(r);
08625                 }
08626         } else {
08627                 if ( clip != 0) {
08628                         ret = image->get_clip(r);
08629                 } else {
08630                         ret = image->copy();
08631                 }
08632         }
08633         return ret;
08634 
08635 }

void ScaleTransformProcessor::process_inplace ( EMData image  )  [virtual]

Exceptions:
ImageDimensionException if the image is not 2D or 3D
InvalidParameterException if the Transform parameter is not specified

Implements EMAN::Processor.

Definition at line 8516 of file processor.cpp.

References EMAN::EMData::clip_inplace(), EMAN::EMData::get_ndim(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Dict::has_key(), ImageDimensionException, InvalidParameterException, EMAN::Processor::params, EMAN::EMData::process_inplace(), EMAN::Dict::set_default(), t, and UnexpectedBehaviorException.

08516                                                            {
08517         int ndim = image->get_ndim();
08518         if (ndim != 2 && ndim != 3) throw UnexpectedBehaviorException("The Scale Transform processors only works for 2D and 3D images");
08519 
08520         if ( image->get_xsize() != image->get_ysize()) {
08521                 throw ImageDimensionException("x size and y size of image do not match. This processor only works for uniformly sized data");
08522         }
08523         if ( ndim == 3 ) {
08524                 if ( image->get_xsize() != image->get_zsize()) {
08525                 throw ImageDimensionException("x size and z size of image do not match. This processor only works for uniformly sized data");
08526                 }
08527         }
08528 
08529         float scale = params.set_default("scale",0.0f);
08530         if (scale <= 0.0f) throw InvalidParameterException("The scale parameter must be greater than 0");
08531 
08532         int clip = 0;
08533 
08534         if(params.has_key("clip"))
08535         {
08536                 clip = params["clip"];
08537                 if (clip < 0) throw InvalidParameterException("The clip parameter must be greater than 0"); // If it's zero it's not used
08538         }
08539         else
08540         {
08541                 clip = (int)(scale*image->get_xsize());
08542         }
08543 
08544         Region r;
08545         if (ndim == 3) {
08546                  r = Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2,clip, clip,clip);
08547         } else { // ndim == 2 guaranteed by check at beginning of function
08548                  r = Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, clip, clip);
08549         }
08550 
08551         if (scale > 1) {
08552                 if ( clip != 0) {
08553                         image->clip_inplace(r);
08554                 }
08555                 Transform t;
08556                 t.set_scale(scale);
08557                 image->process_inplace("xform",Dict("transform",&t));
08558         } else if (scale < 1) {
08559                 Transform t;
08560                 t.set_scale(scale);
08561                 image->process_inplace("xform",Dict("transform",&t));
08562                 if ( clip != 0) {
08563                         image->clip_inplace(r);
08564                 }
08565         } else {
08566                 if ( clip != 0) {
08567                         image->clip_inplace(r);
08568                 }
08569         }
08570 }


Member Data Documentation

const string ScaleTransformProcessor::NAME = "xform.scale" [static]

Definition at line 1621 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Mon May 2 13:30:05 2011 for EMAN2 by  doxygen 1.4.7