--- /dev/null
+#ifndef __bbPackRecalageImageConvolution_h_INCLUDED__
+#define __bbPackRecalageImageConvolution_h_INCLUDED__
+#include "bbPackRecalage_EXPORT.h"
+#include "bbtkAtomicBlackBox.h"
+#include "iostream"
+
+#include "vtkImageData.h"
+#include "Convolution.h"
+
+namespace bbPackRecalage
+{
+
+class bbPackRecalage_EXPORT ImageConvolution
+ :
+ public bbtk::AtomicBlackBox
+{
+ BBTK_BLACK_BOX_INTERFACE(ImageConvolution,bbtk::AtomicBlackBox);
+ BBTK_DECLARE_INPUT(In,vtkImageData*);
+ BBTK_DECLARE_INPUT(Factor,double);
+ BBTK_DECLARE_OUTPUT(Out,vtkImageData*);
+ BBTK_PROCESS(Process);
+ void Process();
+
+ private:
+ Convolution* convolution;
+};
+
+BBTK_BEGIN_DESCRIBE_BLACK_BOX(ImageConvolution,bbtk::AtomicBlackBox);
+BBTK_NAME("ImageConvolution");
+BBTK_AUTHOR("jn.trillos44@uniandes.edu.co");
+BBTK_DESCRIPTION("Processes an image through different convolution matrix (Edge detect)");
+BBTK_CATEGORY("filter");
+BBTK_INPUT(ImageConvolution,In,"Image to be filetered",vtkImageData*,"");
+BBTK_INPUT(ImageConvolution,Factor,"Factor by how the edges will be represented",double,"");
+BBTK_OUTPUT(ImageConvolution,Out,"Filtered Image",vtkImageData*,"");
+BBTK_END_DESCRIBE_BLACK_BOX(ImageConvolution);
+}
+// EO namespace bbPackRecalage
+
+#endif // __bbPackRecalageImageConvolution_h_INCLUDED__
+
#include "bbPackRecalagePackage.h"
namespace bbPackRecalage
{
-
- MyImageSubstraction::MyImageSubstraction(vtkImageData* imageData1,vtkImageData* imageData2, int uZLevel,int lZLevel, std::vector<double> uColor, std::vector<double> lColor, std::vector<double> mColor)
-{
- imageResult= vtkImageData::New();
- sizeImage=0;
- uZeroLevel=uZLevel;
- lZeroLevel=lZLevel;
- if(uColor.size() != NULL)
- {
- upperColor[0] = uColor[0];
- upperColor[1] = uColor[1];
- upperColor[2] = uColor[2];
- }
- else
- {
- upperColor[0] = 255;
- upperColor[1] = 255;
- upperColor[2] = 255;
- }
- if(mColor.size() != NULL)
- {
- mediumColor[0] = mColor[0];
- mediumColor[1] = mColor[1];
- mediumColor[2] = mColor[2];
- }
- else
- {
- mediumColor[0] = 125;
- mediumColor[1] = 125;
- mediumColor[2] = 125;
- }
- if(lColor.size() != NULL)
- {
- lowerColor[0] = lColor[0];
- lowerColor[1] = lColor[1];
- lowerColor[2] = lColor[2];
- }
- else
- {
- lowerColor[0] = 0;
- lowerColor[1] = 0;
- lowerColor[2] = 0;
- }
-
- //Original image type this case is an unsigned char (3)
- int t=imageData1->GetScalarType();
- //substracting the image
- substractImage(imageData1, imageData2);
-}
-
-MyImageSubstraction::~MyImageSubstraction()
-{
- if(imageResult!=NULL)imageResult->Delete();
-}
-
-//----------------------------------------------------------------------------
-// Methods
-//----------------------------------------------------------------------------
-
-
-/*
-Calculate the new image and save it in the attribute imageResult
-it is used if the user had given the imageData
-*/
-void MyImageSubstraction::substractImage(vtkImageData* imageData1, vtkImageData* imageData2)
-{
- //dimensions of the image (extent)
- int ext[6];
- //setting the dimensionality (1d or 2d or 3d )
- int newDim[3];
- //image spacing
- double spc[3];
-
- //getting the information from the original image
- imageData1->GetSpacing(spc);
- imageData1->GetExtent(ext);
-
- //this a 2d image
- newDim[0]=ext[1]-ext[0]+1;
- newDim[1]=ext[3]-ext[2]+1;
- newDim[2]=1;// in general it is ext[5]-ext[4]+1
-
-
- //initializing the image that represents the substracted image
- initialize(newDim,spc);
- //Time to substract
- substract(imageData1, imageData2);
-}
-
-/*
- getting ready the imageResult
-*/
-void MyImageSubstraction::initialize(int dimensions[], double spacing[])
-{
- //setting image data of the imageResult
- imageResult->SetScalarTypeToUnsignedChar();
- imageResult->SetSpacing(spacing);
- imageResult->SetDimensions(dimensions);
- imageResult->AllocateScalars();
- imageResult->Update();
-}
-
-/*
- Setting the values for the
-*/
-void MyImageSubstraction::substract(vtkImageData* imageData1, vtkImageData* imageData2)
-{
- /*
- images pointers
- */
- //the new image type is unsigned short (5)
- int t=imageData1->GetScalarType();
-
- // pointers to get into the image
- unsigned char* dataImagePointer1=NULL;
- unsigned char* dataImagePointer2=NULL;
- unsigned char* dataImageResultPointer=NULL;
- // we start where the image starts
- dataImagePointer1=(unsigned char*)imageData1->GetScalarPointer(0,0,0);
- dataImagePointer2=(unsigned char*)imageData2->GetScalarPointer(0,0,0);
- dataImageResultPointer=(unsigned char*)imageResult->GetScalarPointer(0,0,0);
-
- /*
- Image Size
- */
- int ext[6];
- imageData1->GetExtent(ext);
- int sx,sy,sz;
- sx=ext[1]-ext[0]+1;
- sy=ext[3]-ext[2]+1;
- sz=ext[5]-ext[4]+1;
-
- sizeImage=sx*sy*sz;
-
- //-----------------
- //A3
- //-----------------
- //walking in the image
- int i=0,j=0,k=0,counter=0,nU=0,nL=0,nZ=0;
- double sum1=0,sum2=0;
- for(i=0;i<sx;i++)
- {
- for(j=0;j<sy;j++)
- {
- for(k=0;k<sz;k++)
- {
-
- // this is for getting just the grey level in that position
- //originalValue=(short)imageData->GetScalarComponentAsFloat(i,j,k,0);
-
- // we get the pointer to the position (i,j,k)y that way we can get the
- //grey level and we can change it
- dataImagePointer1=(unsigned char*)imageData1->GetScalarPointer(i,j,k);
- dataImagePointer2=(unsigned char*)imageData2->GetScalarPointer(i,j,k);
- dataImageResultPointer=(unsigned char*)imageResult->GetScalarPointer(i,j,k);
-
- sum1=(int)(dataImagePointer1[0]) + (int)(dataImagePointer1[1]) + (int)(dataImagePointer1[2]);
- sum1=sum1/3;
- sum2=(int)(dataImagePointer2[0]) + (int)(dataImagePointer2[1]) + (int)(dataImagePointer2[2]);
- sum2=sum2/3;
- if((sum1 - sum2) < lZeroLevel)
- {
- dataImageResultPointer[0] =(unsigned char) lowerColor[0];
- dataImageResultPointer[1] =(unsigned char) lowerColor[1];
- dataImageResultPointer[2] =(unsigned char) lowerColor[2];
- nL++;
- }
- else if((sum1 - sum2) > uZeroLevel)
- {
- dataImageResultPointer[0] =(unsigned char) upperColor[0];
- dataImageResultPointer[1] =(unsigned char) upperColor[1];
- dataImageResultPointer[2] =(unsigned char) upperColor[2];
- nU++;
- }
- else
- {
- dataImageResultPointer[0] =(unsigned char) mediumColor[0];
- dataImageResultPointer[1] =(unsigned char) mediumColor[1];
- dataImageResultPointer[2] =(unsigned char) mediumColor[2];
- nZ++;
- }
- counter++;
- }
- }
- }
-}
-/*
-Returns the filtered image
-*/
-vtkImageData* MyImageSubstraction::getSubstractedImage()
-{
- return imageResult;
-}
-
-/*
- Get Image Size
-*/
-int MyImageSubstraction::getImageSize()
-{
- return sizeImage;
-}
-
BBTK_ADD_BLACK_BOX_TO_PACKAGE(PackRecalage,ImageSubstraction)
BBTK_BLACK_BOX_IMPLEMENTATION(ImageSubstraction,bbtk::AtomicBlackBox);
void ImageSubstraction::Process()
{
- MyImageSubstraction* subImage = new MyImageSubstraction(bbGetInputIn1(),bbGetInputIn2(),bbGetInputIn3(),bbGetInputIn4(),bbGetInputInU(),bbGetInputInL(),bbGetInputInM());
+ subImage = new Substraction(bbGetInputIn1(),bbGetInputIn2(),bbGetInputIn3(),bbGetInputIn4(),bbGetInputInU(),bbGetInputInL(),bbGetInputInM());
bbSetOutputOut(subImage->getSubstractedImage());
}
bbSetInputInU(vector);
bbSetInputInM(vector);
bbSetInputInL(vector);
+ subImage = NULL;
}
void ImageSubstraction::bbUserInitializeProcessing()
// THE FINALIZATION METHOD BODY :
// Here does nothing
// but this is where you should desallocate the internal/output pointers
-// if any
+// if any
}
}
#include <string>
#include <vector>
+#include "Substraction.h"
-namespace bbPackRecalage
-{
- class MyImageSubstraction
+namespace bbPackRecalage
{
-
- //----------------------------------------------------------------------------------------
- // Methods definition
- //----------------------------------------------------------------------------------------
- public:
- //--------------------------
- //Constructor & Destructor
- //--------------------------
- MyImageSubstraction(vtkImageData* imageData1, vtkImageData* imageData2, int uZLevel,int lZLevel, std::vector<double> uColor, std::vector<double> lColor, std::vector<double> mColor);
- ~MyImageSubstraction();
- //--------------------------
- //Methods
- //--------------------------
- /*
- getting ready the points
- */
- void initialize(int dimensions[],double spacing[]);
- /*
- Calculate the new image and save it in the attribute imageResult
- it is used if the user had given the imageData
- */
- void substractImage(vtkImageData* imageData1, vtkImageData* imageData2);
-
- /*
- Returns the ImageResult
- */
- vtkImageData* getSubstractedImage();
-
- /*
- Get Image Size
- */
- int getImageSize();
-
- /*
- constructing image substract
- */
- void substract(vtkImageData* imageData1, vtkImageData* imageData2);
-
-
-
- //----------------------------------------------------------------------------------------
- // Attributes declaration
- //----------------------------------------------------------------------------------------
- private:
- /*
- Substracted Image
- */
- vtkImageData* imageResult;
- /*
- image size dimx*dimy*dimz
- */
- int sizeImage;
- /*
- upper zero level for doing the Substraction
- */
- int uZeroLevel;
- /*
- lower zero level for doing the Substraction
- */
- int lZeroLevel;
- /*
- Color for the upper threshold
- */
- int upperColor[3];
- /*
- Color for the lower threshold
- */
- int lowerColor[3];
- /*
- Color for the medium threshold
- */
- int mediumColor[3];
-};
-
class bbPackRecalage_EXPORT ImageSubstraction
:
public bbtk::AtomicBlackBox
BBTK_DECLARE_OUTPUT(Out,vtkImageData*);
BBTK_PROCESS(Process);
void Process();
+
+ private:
+ Substraction* subImage;
};
BBTK_BEGIN_DESCRIBE_BLACK_BOX(ImageSubstraction,bbtk::AtomicBlackBox);