EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes
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:
ImageDimensionExceptionif the image is not 2D or 3D
InvalidParameterExceptionif the Transform parameter is not specified

virtual EMDataprocess (const EMData *const image)
 
Exceptions:
ImageDimensionExceptionif the image is not 2D or 3D
InvalidParameterExceptionif 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:
scaleThe amount by which to scale
cipThe length of each output dimension. Non sophisticated, output dimensions can't be different

Definition at line 1795 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 1828 of file processor.h.

                        {
                                return "The image is scaled with the clip variable in mind, being sure to preserve as much pixel information as possible.";
                        }
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 1798 of file processor.h.

References NAME.

                        {
                                return NAME;
                        }
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.

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

Reimplemented from EMAN::Processor.

Definition at line 1818 of file processor.h.

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

                        {
                                TypeDict d;
                                d.put("scale", EMObject::FLOAT, "The amount by which to scale" );
                                d.put("clip", EMObject::INT, "The length of each output dimension. Non sophisticated, output dimensions can't be different" );
                                return d;
                        }
static Processor* EMAN::ScaleTransformProcessor::NEW ( ) [inline, static]

Definition at line 1802 of file processor.h.

                        {
                                return new ScaleTransformProcessor();
                        }
EMData * ScaleTransformProcessor::process ( const EMData *const  image) [virtual]

Exceptions:
ImageDimensionExceptionif the image is not 2D or 3D
InvalidParameterExceptionif the Transform parameter is not specified

Reimplemented from EMAN::Processor.

Definition at line 9475 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(), EMAN::Transform::set_scale(), t, and UnexpectedBehaviorException.

                                                                  {
        int ndim = image->get_ndim();
        if (ndim != 2 && ndim != 3) throw UnexpectedBehaviorException("The Scale Transform processors only works for 2D and 3D images");

        if ( image->get_xsize() != image->get_ysize()) {
                throw ImageDimensionException("x size and y size of image do not match. This processor only works for uniformly sized data");
        }
        if ( ndim == 3 ) {
                if ( image->get_xsize() != image->get_zsize()) {
                throw ImageDimensionException("x size and z size of image do not match. This processor only works for uniformly sized data");
                }
        }

        float scale = params.set_default("scale",0.0f);
        if (scale <= 0.0f) throw InvalidParameterException("The scale parameter must be greater than 0");

        int clip = 0;

        if(params.has_key("clip"))
        {
                clip = params["clip"];
                if (clip < 0) throw InvalidParameterException("The clip parameter must be greater than 0"); // If it's zero it's not used
        }
        else
        {
                clip = (int)(scale*image->get_xsize());
        }

        Region r;
        if (ndim == 3) {
                 r = Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2,clip, clip,clip);
        } else { // ndim == 2 guaranteed by check at beginning of function
                 r = Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, clip, clip);
        }

        EMData* ret = 0;
        if (scale > 1) {
                if ( clip != 0) {
                        ret = image->get_clip(r);
                }
                Transform t;
                t.set_scale(scale);
                if (ret != 0) {
                        ret->process_inplace("xform",Dict("transform",&t));
                } else {
                        ret = image->process("xform",Dict("transform",&t));
                }
        } else if (scale < 1) {
                Transform t;
                t.set_scale(scale);
                ret = image->process("xform",Dict("transform",&t));
                if ( clip != 0) {
                        ret->clip_inplace(r);
                }
        } else {
                if ( clip != 0) {
                        ret = image->get_clip(r);
                } else {
                        ret = image->copy();
                }
        }
        return ret;

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

Exceptions:
ImageDimensionExceptionif the image is not 2D or 3D
InvalidParameterExceptionif the Transform parameter is not specified

Implements EMAN::Processor.

Definition at line 9224 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(), EMAN::Transform::set_scale(), t, and UnexpectedBehaviorException.

                                                           {
        int ndim = image->get_ndim();
        if (ndim != 2 && ndim != 3) throw UnexpectedBehaviorException("The Scale Transform processors only works for 2D and 3D images");

        if ( image->get_xsize() != image->get_ysize()) {
                throw ImageDimensionException("x size and y size of image do not match. This processor only works for uniformly sized data");
        }
        if ( ndim == 3 ) {
                if ( image->get_xsize() != image->get_zsize()) {
                throw ImageDimensionException("x size and z size of image do not match. This processor only works for uniformly sized data");
                }
        }

        float scale = params.set_default("scale",0.0f);
        if (scale <= 0.0f) throw InvalidParameterException("The scale parameter must be greater than 0");

        int clip = 0;

        if(params.has_key("clip"))
        {
                clip = params["clip"];
                if (clip < 0) throw InvalidParameterException("The clip parameter must be greater than 0"); // If it's zero it's not used
        }
        else
        {
                clip = (int)(scale*image->get_xsize());
        }

        Region r;
        if (ndim == 3) {
                 r = Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2,clip, clip,clip);
        } else { // ndim == 2 guaranteed by check at beginning of function
                 r = Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, clip, clip);
        }

        if (scale > 1) {
                if ( clip != 0) {
                        image->clip_inplace(r);
                }
                Transform t;
                t.set_scale(scale);
                image->process_inplace("xform",Dict("transform",&t));
        } else if (scale < 1) {
                Transform t;
                t.set_scale(scale);
                image->process_inplace("xform",Dict("transform",&t));
                if ( clip != 0) {
                        image->clip_inplace(r);
                }
        } else {
                if ( clip != 0) {
                        image->clip_inplace(r);
                }
        }
}

Member Data Documentation

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

Definition at line 1833 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files: