Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

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)
virtual EMDataprocess (const EMData *const image)
virtual TypeDict get_param_types () const
virtual string get_desc () const
 Get the descrition of this specific processor.

Static Public Member Functions

ProcessorNEW ()

Static Public Attributes

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 1617 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 1650 of file processor.h.

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

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 1620 of file processor.h.

01621                         {
01622                                 return NAME;
01623                         }

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

d.put("clipx", EMObject::INT, "The length of the output x dimension. Exclusive of the clip.");

Reimplemented from EMAN::Processor.

Definition at line 1640 of file processor.h.

References EMAN::TypeDict::put().

01641                         {
01642                                 TypeDict d;
01643                                 d.put("scale", EMObject::FLOAT, "The amount by which to scale" );
01644                                 d.put("clip", EMObject::INT, "The length of each output dimension. Non sophisticated, output dimensions can't be different" );
01647                                 return d;
01648                         }

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

Definition at line 1624 of file processor.h.

01625                         {
01626                                 return new ScaleTransformProcessor();
01627                         }

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 8689 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::EMData::process(), EMAN::EMData::process_inplace(), EMAN::Dict::set_default(), EMAN::Transform::set_scale(), t, and UnexpectedBehaviorException.

08689                                                                   {
08690         int ndim = image->get_ndim();
08691         if (ndim != 2 && ndim != 3) throw UnexpectedBehaviorException("The Scale Transform processors only works for 2D and 3D images");
08692 
08693         if ( image->get_xsize() != image->get_ysize()) {
08694                 throw ImageDimensionException("x size and y size of image do not match. This processor only works for uniformly sized data");
08695         }
08696         if ( ndim == 3 ) {
08697                 if ( image->get_xsize() != image->get_zsize()) {
08698                 throw ImageDimensionException("x size and z size of image do not match. This processor only works for uniformly sized data");
08699                 }
08700         }
08701 
08702         float scale = params.set_default("scale",0.0f);
08703         if (scale <= 0.0f) throw InvalidParameterException("The scale parameter must be greater than 0");
08704 
08705         int clip = 0;
08706 
08707         if(params.has_key("clip"))
08708         {
08709                 clip = params["clip"];
08710                 if (clip < 0) throw InvalidParameterException("The clip parameter must be greater than 0"); // If it's zero it's not used
08711         }
08712         else
08713         {
08714                 clip = (int)(scale*image->get_xsize());
08715         }
08716 
08717         Region r;
08718         if (ndim == 3) {
08719                  r = Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2,clip, clip,clip);
08720         } else { // ndim == 2 guaranteed by check at beginning of function
08721                  r = Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, clip, clip);
08722         }
08723 
08724         EMData* ret = 0;
08725         if (scale > 1) {
08726                 if ( clip != 0) {
08727                         ret = image->get_clip(r);
08728                 }
08729                 Transform t;
08730                 t.set_scale(scale);
08731                 if (ret != 0) {
08732                         ret->process_inplace("xform",Dict("transform",&t));
08733                 } else {
08734                         ret = image->process("xform",Dict("transform",&t));
08735                 }
08736         } else if (scale < 1) {
08737                 Transform t;
08738                 t.set_scale(scale);
08739                 ret = image->process("xform",Dict("transform",&t));
08740                 if ( clip != 0) {
08741                         ret->clip_inplace(r);
08742                 }
08743         } else {
08744                 if ( clip != 0) {
08745                         ret = image->get_clip(r);
08746                 } else {
08747                         ret = image->copy();
08748                 }
08749         }
08750         return ret;
08751 
08752 }

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 8633 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::EMData::process_inplace(), EMAN::Dict::set_default(), EMAN::Transform::set_scale(), t, and UnexpectedBehaviorException.

08633                                                            {
08634         int ndim = image->get_ndim();
08635         if (ndim != 2 && ndim != 3) throw UnexpectedBehaviorException("The Scale Transform processors only works for 2D and 3D images");
08636 
08637         if ( image->get_xsize() != image->get_ysize()) {
08638                 throw ImageDimensionException("x size and y size of image do not match. This processor only works for uniformly sized data");
08639         }
08640         if ( ndim == 3 ) {
08641                 if ( image->get_xsize() != image->get_zsize()) {
08642                 throw ImageDimensionException("x size and z size of image do not match. This processor only works for uniformly sized data");
08643                 }
08644         }
08645 
08646         float scale = params.set_default("scale",0.0f);
08647         if (scale <= 0.0f) throw InvalidParameterException("The scale parameter must be greater than 0");
08648 
08649         int clip = 0;
08650 
08651         if(params.has_key("clip"))
08652         {
08653                 clip = params["clip"];
08654                 if (clip < 0) throw InvalidParameterException("The clip parameter must be greater than 0"); // If it's zero it's not used
08655         }
08656         else
08657         {
08658                 clip = (int)(scale*image->get_xsize());
08659         }
08660 
08661         Region r;
08662         if (ndim == 3) {
08663                  r = Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2,clip, clip,clip);
08664         } else { // ndim == 2 guaranteed by check at beginning of function
08665                  r = Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, clip, clip);
08666         }
08667 
08668         if (scale > 1) {
08669                 if ( clip != 0) {
08670                         image->clip_inplace(r);
08671                 }
08672                 Transform t;
08673                 t.set_scale(scale);
08674                 image->process_inplace("xform",Dict("transform",&t));
08675         } else if (scale < 1) {
08676                 Transform t;
08677                 t.set_scale(scale);
08678                 image->process_inplace("xform",Dict("transform",&t));
08679                 if ( clip != 0) {
08680                         image->clip_inplace(r);
08681                 }
08682         } else {
08683                 if ( clip != 0) {
08684                         image->clip_inplace(r);
08685                 }
08686         }
08687 }


Member Data Documentation

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

Definition at line 88 of file processor.cpp.


The documentation for this class was generated from the following files:
Generated on Thu Nov 17 12:45:56 2011 for EMAN2 by  doxygen 1.3.9.1