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

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

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

References NAME.

01490                                 {
01491                                         return NAME;
01492                                 }

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

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

01511                                 {
01512                                         TypeDict d;
01513                                         d.put("scale", EMObject::FLOAT, "The amount by which to scale" );
01514                                         d.put("clip", EMObject::INT, "The length of each output dimension. Non sophisticated, output dimensions can't be different" );
01517                                         return d;
01518                                 }

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

Definition at line 1493 of file processor.h.

01494                                 {
01495                                         return new ScaleTransformProcessor();
01496                                 }

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

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

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

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


Member Data Documentation

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

Definition at line 1525 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Mon Mar 7 18:09:41 2011 for EMAN2 by  doxygen 1.4.7