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

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

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

01405                                 {
01406                                         return NAME;
01407                                 }

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

References EMAN::TypeDict::put().

01426                                 {
01427                                         TypeDict d;
01428                                         d.put("scale", EMObject::FLOAT, "The amount by which to scale" );
01429                                         d.put("clip", EMObject::INT, "The length of each output dimension. Non sophisticated, output dimensions can't be different" );
01432                                         return d;
01433                                 }

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

Definition at line 1408 of file processor.h.

01409                                 {
01410                                         return new ScaleTransformProcessor();
01411                                 }

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

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

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

08467                                                            {
08468         int ndim = image->get_ndim();
08469         if (ndim != 2 && ndim != 3) throw UnexpectedBehaviorException("The Scale Transform processors only works for 2D and 3D images");
08470 
08471         if ( image->get_xsize() != image->get_ysize()) {
08472                 throw ImageDimensionException("x size and y size of image do not match. This processor only works for uniformly sized data");
08473         }
08474         if ( ndim == 3 ) {
08475                 if ( image->get_xsize() != image->get_zsize()) {
08476                 throw ImageDimensionException("x size and z size of image do not match. This processor only works for uniformly sized data");
08477                 }
08478         }
08479 
08480         float scale = params.set_default("scale",0.0f);
08481         if (scale <= 0.0f) throw InvalidParameterException("The scale parameter must be greater than 0");
08482 
08483         int clip = 0;
08484 
08485         if(params.has_key("clip"))
08486         {
08487                 clip = params["clip"];
08488                 if (clip < 0) throw InvalidParameterException("The clip parameter must be greater than 0"); // If it's zero it's not used
08489         }
08490         else
08491         {
08492                 clip = (int)(scale*image->get_xsize());
08493         }
08494 
08495         Region r;
08496         if (ndim == 3) {
08497                  r = Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2,clip, clip,clip);
08498         } else { // ndim == 2 guaranteed by check at beginning of function
08499                  r = Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, clip, clip);
08500         }
08501 
08502         if (scale > 1) {
08503                 if ( clip != 0) {
08504                         image->clip_inplace(r);
08505                 }
08506                 Transform t;
08507                 t.set_scale(scale);
08508                 image->process_inplace("xform",Dict("transform",&t));
08509         } else if (scale < 1) {
08510                 Transform t;
08511                 t.set_scale(scale);
08512                 image->process_inplace("xform",Dict("transform",&t));
08513                 if ( clip != 0) {
08514                         image->clip_inplace(r);
08515                 }
08516         } else {
08517                 if ( clip != 0) {
08518                         image->clip_inplace(r);
08519                 }
08520         }
08521 }


Member Data Documentation

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

Definition at line 84 of file processor.cpp.


The documentation for this class was generated from the following files:
Generated on Thu Dec 9 13:47:44 2010 for EMAN2 by  doxygen 1.3.9.1