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

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

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

References NAME.

01666                         {
01667                                 return NAME;
01668                         }

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

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

01686                         {
01687                                 TypeDict d;
01688                                 d.put("scale", EMObject::FLOAT, "The amount by which to scale" );
01689                                 d.put("clip", EMObject::INT, "The length of each output dimension. Non sophisticated, output dimensions can't be different" );
01692                                 return d;
01693                         }

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

Definition at line 1669 of file processor.h.

01670                         {
01671                                 return new ScaleTransformProcessor();
01672                         }

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 8761 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.

08761                                                                   {
08762         int ndim = image->get_ndim();
08763         if (ndim != 2 && ndim != 3) throw UnexpectedBehaviorException("The Scale Transform processors only works for 2D and 3D images");
08764 
08765         if ( image->get_xsize() != image->get_ysize()) {
08766                 throw ImageDimensionException("x size and y size of image do not match. This processor only works for uniformly sized data");
08767         }
08768         if ( ndim == 3 ) {
08769                 if ( image->get_xsize() != image->get_zsize()) {
08770                 throw ImageDimensionException("x size and z size of image do not match. This processor only works for uniformly sized data");
08771                 }
08772         }
08773 
08774         float scale = params.set_default("scale",0.0f);
08775         if (scale <= 0.0f) throw InvalidParameterException("The scale parameter must be greater than 0");
08776 
08777         int clip = 0;
08778 
08779         if(params.has_key("clip"))
08780         {
08781                 clip = params["clip"];
08782                 if (clip < 0) throw InvalidParameterException("The clip parameter must be greater than 0"); // If it's zero it's not used
08783         }
08784         else
08785         {
08786                 clip = (int)(scale*image->get_xsize());
08787         }
08788 
08789         Region r;
08790         if (ndim == 3) {
08791                  r = Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2,clip, clip,clip);
08792         } else { // ndim == 2 guaranteed by check at beginning of function
08793                  r = Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, clip, clip);
08794         }
08795 
08796         EMData* ret = 0;
08797         if (scale > 1) {
08798                 if ( clip != 0) {
08799                         ret = image->get_clip(r);
08800                 }
08801                 Transform t;
08802                 t.set_scale(scale);
08803                 if (ret != 0) {
08804                         ret->process_inplace("xform",Dict("transform",&t));
08805                 } else {
08806                         ret = image->process("xform",Dict("transform",&t));
08807                 }
08808         } else if (scale < 1) {
08809                 Transform t;
08810                 t.set_scale(scale);
08811                 ret = image->process("xform",Dict("transform",&t));
08812                 if ( clip != 0) {
08813                         ret->clip_inplace(r);
08814                 }
08815         } else {
08816                 if ( clip != 0) {
08817                         ret = image->get_clip(r);
08818                 } else {
08819                         ret = image->copy();
08820                 }
08821         }
08822         return ret;
08823 
08824 }

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 8705 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.

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


Member Data Documentation

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

Definition at line 1700 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Thu May 3 10:09:49 2012 for EMAN2 by  doxygen 1.4.7