Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

ConvenienceProcessors.hxx

00001 /* ImLib3D
00002  * Copyright (c) 2001, ULP-IPB Strasbourg.
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or (at
00007  * your option) any later version.
00008  * 
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00018 
00020 #ifndef _ConvenienceProcessors_hxx
00021 #define _ConvenienceProcessors_hxx
00022 
00023 #include<ImLib3D/ConvenienceProcessors.hpp>
00024 #include<ImLib3D/Threshold.hpp>
00025 #include<ImLib3D/Transformation.hpp>
00026 
00027 template <class ImageType>
00028 void
00029 IP3D::Crop(const ImageType& src,const RectZone3Di &zone,ImageType& res0)
00030 {
00031     ImageProcessorArgs<ImageType> args(ImArgs(src),res0);
00032     ImageType &res=args.GetDest();
00033     res.properties=src.properties;
00034     // check coherence
00035     if(!(src.IsInside(zone.GetP0()) && src.IsInside(zone.GetP1())))
00036     {
00037         ThrowError("IP3D::Crop: subimage not in image");
00038     }
00039     typename ImageType::const_iteratorZone p(zone);
00040     res.Resize(Size3D(zone.Width(),zone.Height(),zone.Depth()));
00041     for( p=src.begin(); p!=src.end(); ++p )
00042     {
00043         res(p.Pos()-zone.GetP0())=*p;
00044     }
00045     // also crop mask if needed 
00046     if(src.HasMask())
00047     {
00048         IP3D::Crop(src.Mask(),zone,res.Mask());
00049     }
00050 }
00051 
00052 
00053 
00054 template <class ImageType>
00055 void
00056 IP3D::ApplyMask(const ImageType& src, ImageType& res, byte maskvalue, const Mask3D* optmask)
00057 {
00058     Mask3D mask;
00059     if (optmask){ mask = *optmask;}
00060     else
00061     { 
00062         if(!src.HasMask()){ThrowError("GetMask: no mask");}
00063         mask = src.Mask();
00064     }
00065     if (maskvalue > 0) {IP3D::SimpleThresholds2(mask, maskvalue, maskvalue, mask);}
00066     res = src;
00067     mask.ApplyOn(res);
00068 }
00069 
00070 
00071 template <class ComplexImageType>
00072 void
00073 IP3D::ExtractFromComplexImage(const ComplexImageType& src,const string&type,Image3Df &res)
00074 {
00075     if(type=="Imag"  ) {src.ComplexImag(res)  ;}
00076     else
00077     if(type=="Real"  ) {src.ComplexReal(res)  ;}
00078     else
00079     if(type=="Norm2" ) {src.ComplexNorm2(res) ;}
00080     else
00081     if(type=="Module") {src.ComplexModule(res);}
00082     else
00083     if(type=="CenteredLogModule") 
00084     {
00085         src.ComplexModule(res);
00086         for(Image3Df::iteratorFast p=res.begin();p!=res.end();++p)
00087         {
00088             if(*p){*p=log(*p);}
00089             else{*p=0;}
00090         }
00091         IP3D::WrapTranslate(res,res.SizeV()/2,res);
00092     }
00093     else
00094     {ThrowError("ExtractFromComplexImage:: unknown type:%s",type);}
00095 }
00096 
00097 #endif// _ConvenienceProcessors_hxx

Generated on Fri Jun 17 13:35:58 2005 for ImLib3D by  doxygen 1.4.2