#include <processor.h>

Protected Member Functions | |
| template<class LogicOp> | |
| EMData * | process (const EMData *const image, Dict ¶ms) |
| Boolean shrink an image, returning the processed image. | |
| template<class LogicOp> | |
| void | process_inplace (EMData *image, Dict ¶ms) |
| Boolean shrink an image inplace. | |
Both of these instances are written at compile time using templates.
Definition at line 3027 of file processor.h.
| EMData * BooleanShrinkProcessor::process | ( | const EMData *const | image, | |
| Dict & | params | |||
| ) | [inline, protected] |
Boolean shrink an image, returning the processed image.
| image | the image to operate on | |
| params | parameter dictionary |
| ImageFormatException | if the image is complex | |
| NullPointerException | if the image pointer is null |
Definition at line 1904 of file processor.cpp.
References EMAN::EMData::copy(), EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageFormatException, InvalidValueException, EMAN::EMData::is_complex(), NullPointerException, EMAN::Dict::set_default(), EMAN::EMData::set_size(), EMAN::EMData::set_value_at(), EMAN::EMData::update(), and x.
01905 { 01906 // The basic idea of this code is to iterate through each pixel in the output image 01907 // determining its value by investigation a region of the input image 01908 01909 if (!image) throw NullPointerException("Attempt to max shrink a null image"); 01910 01911 if (image->is_complex() ) throw ImageFormatException("Can not max shrink a complex image"); 01912 01913 01914 int shrink = params.set_default("n",2); 01915 int search = params.set_default("search",2); 01916 01917 if ( shrink < 0 ) throw InvalidValueException(shrink, "Can not shrink by a value less than 0"); 01918 01919 01920 int nz = image->get_zsize(); 01921 int ny = image->get_ysize(); 01922 int nx = image->get_xsize(); 01923 01924 if (nx == 1 && ny == 1 && nz == 1 ) return image->copy(); 01925 01926 LogicOp op; 01927 EMData* return_image = new EMData(); 01928 01929 int shrinkx = shrink; 01930 int shrinky = shrink; 01931 int shrinkz = shrink; 01932 01933 int searchx = search; 01934 int searchy = search; 01935 int searchz = search; 01936 01937 // Clamping the shrink values to the dimension lengths 01938 // ensures that the return image has non zero dimensions 01939 if ( shrinkx > nx ) shrinkx = nx; 01940 if ( shrinky > ny ) shrinky = ny; 01941 if ( shrinkz > nz ) shrinkz = nz; 01942 01943 if ( nz == 1 && ny == 1 ) 01944 { 01945 return_image->set_size(nx/shrinkx); 01946 for(int i = 0; i < nx/shrinkx; ++i) 01947 { 01948 float tmp = op.get_start_val(); 01949 for(int s=0; s < searchx; ++s) 01950 { 01951 int idx = shrinkx*i+s; 01952 // Don't ask for memory beyond limits 01953 if ( idx > nx ) break; 01954 else 01955 { 01956 float val = image->get_value_at(idx); 01957 if ( op( val,tmp) ) tmp = val; 01958 } 01959 } 01960 return_image->set_value_at(i,tmp); 01961 } 01962 } 01963 else if ( nz == 1 ) 01964 { 01965 int ty = ny/shrinky; 01966 int tx = nx/shrinkx; 01967 return_image->set_size(tx,ty); 01968 for(int y = 0; y < ty; ++y) { 01969 for(int x = 0; x < tx; ++x) { 01970 float tmp = op.get_start_val(); 01971 for(int sy=0; sy < searchy; ++sy) { 01972 int yidx = shrinky*y+sy; 01973 if ( yidx >= ny) break; 01974 for(int sx=0; sx < searchx; ++sx) { 01975 int xidx = shrinkx*x+sx; 01976 if ( xidx >= nx) break; 01977 01978 float val = image->get_value_at(xidx,yidx); 01979 if ( op( val,tmp) ) tmp = val; 01980 } 01981 } 01982 return_image->set_value_at(x,y,tmp); 01983 } 01984 } 01985 } 01986 else 01987 { 01988 int tz = nz/shrinkz; 01989 int ty = ny/shrinky; 01990 int tx = nx/shrinkx; 01991 01992 return_image->set_size(tx,ty,tz); 01993 for(int z = 0; z < tz; ++z) { 01994 for(int y = 0; y < ty; ++y) { 01995 for(int x = 0; x < tx; ++x) { 01996 float tmp = op.get_start_val(); 01997 01998 for(int sz=0; sz < searchz; ++sz) { 01999 int zidx = shrinkz*z+sz; 02000 if ( zidx >= nz) break; 02001 02002 for(int sy=0; sy < searchy; ++sy) { 02003 int yidx = shrinky*y+sy; 02004 if ( yidx >= ny) break; 02005 02006 for(int sx=0; sx < searchx; ++sx) { 02007 int xidx = shrinkx*x+sx; 02008 if ( xidx >= nx) break; 02009 float val = image->get_value_at(xidx,yidx,zidx); 02010 if ( op( val,tmp) ) tmp = val; 02011 } 02012 } 02013 } 02014 return_image->set_value_at(x,y,z,tmp); 02015 } 02016 } 02017 } 02018 } 02019 return_image->update(); 02020 02021 return return_image; 02022 }
| void BooleanShrinkProcessor::process_inplace | ( | EMData * | image, | |
| Dict & | params | |||
| ) | [inline, protected] |
Boolean shrink an image inplace.
| image | the image to operate on | |
| params | parameter dictionary |
| ImageFormatException | if the image is complex | |
| NullPointerException | if the image pointer is null |
Definition at line 2025 of file processor.cpp.
References EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageFormatException, InvalidValueException, EMAN::EMData::is_complex(), NullPointerException, EMAN::Dict::set_default(), EMAN::EMData::set_size(), EMAN::EMData::set_value_at(), EMAN::EMData::update(), and x.
02026 { 02027 // The basic idea of this code is to iterate through each pixel in the output image 02028 // determining its value by investigation a region of the input image 02029 if (!image) throw NullPointerException("Attempt to max shrink a null image"); 02030 02031 if (image->is_complex() ) throw ImageFormatException("Can not max shrink a complex image"); 02032 02033 02034 int shrink = params.set_default("shrink",2); 02035 int search = params.set_default("search",2); 02036 02037 if ( shrink < 0 ) throw InvalidValueException(shrink, "Can not shrink by a value less than 0"); 02038 02039 02040 int nz = image->get_zsize(); 02041 int ny = image->get_ysize(); 02042 int nx = image->get_xsize(); 02043 02044 LogicOp op; 02045 02046 int shrinkx = shrink; 02047 int shrinky = shrink; 02048 int shrinkz = shrink; 02049 02050 int searchx = search; 02051 int searchy = search; 02052 int searchz = search; 02053 02054 // Clamping the shrink values to the dimension lengths 02055 // ensures that the return image has non zero dimensions 02056 if ( shrinkx > nx ) shrinkx = nx; 02057 if ( shrinky > ny ) shrinkx = ny; 02058 if ( shrinkz > nz ) shrinkx = nz; 02059 02060 if (nx == 1 && ny == 1 && nz == 1 ) return; 02061 02062 if ( nz == 1 && ny == 1 ) 02063 { 02064 for(int i = 0; i < nx/shrink; ++i) 02065 { 02066 float tmp = op.get_start_val(); 02067 for(int s=0; s < searchx; ++s) 02068 { 02069 int idx = shrinkx*i+s; 02070 if ( idx > nx ) break; 02071 else 02072 { 02073 float val = image->get_value_at(idx); 02074 if ( op( val,tmp) ) tmp = val; 02075 } 02076 } 02077 image->set_value_at(i,tmp); 02078 } 02079 02080 image->set_size(nx/shrinkx); 02081 } 02082 else if ( nz == 1 ) 02083 { 02084 int ty = ny/shrinky; 02085 int tx = nx/shrinkx; 02086 for(int y = 0; y < ty; ++y) { 02087 for(int x = 0; x < tx; ++x) { 02088 float tmp = op.get_start_val(); 02089 for(int sy=0; sy < searchy; ++sy) { 02090 int yidx = shrinky*y+sy; 02091 if ( yidx >= ny) break; 02092 for(int sx=0; sx < searchx; ++sx) { 02093 int xidx = shrinkx*x+sx; 02094 if ( xidx >= nx) break; 02095 02096 float val = image->get_value_at(xidx,yidx); 02097 if ( op( val,tmp) ) tmp = val; 02098 } 02099 } 02100 (*image)(x+tx*y) = tmp; 02101 } 02102 } 02103 image->set_size(tx,ty); 02104 } 02105 else 02106 { 02107 int tnxy = nx/shrinkx*ny/shrinky; 02108 int tz = nz/shrinkz; 02109 int ty = ny/shrinky; 02110 int tx = nx/shrinkx; 02111 02112 for(int z = 0; z < tz; ++z) { 02113 for(int y = 0; y < ty; ++y) { 02114 for(int x = 0; x < tx; ++x) { 02115 float tmp = op.get_start_val(); 02116 for(int sz=0; sz < searchz; ++sz) { 02117 int zidx = shrinkz*z+sz; 02118 if ( zidx >= nz) break; 02119 for(int sy=0; sy < searchy; ++sy) { 02120 int yidx = shrinky*y+sy; 02121 if ( yidx >= ny) break; 02122 for(int sx=0; sx < shrinkx; ++sx) { 02123 int xidx = shrinkx*x+sx; 02124 if ( xidx >= nx) break; 02125 02126 float val = image->get_value_at(xidx,yidx,zidx); 02127 if ( op( val,tmp) ) tmp = val; 02128 } 02129 } 02130 } 02131 (*image)(x+tx*y+tnxy*z) = tmp; 02132 } 02133 } 02134 } 02135 image->set_size(tx,ty,tz); 02136 } 02137 image->update(); 02138 }
1.5.6