1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
27 //----------------------------------------------------------------------------
28 // Class definition include
29 //----------------------------------------------------------------------------
31 #include "pHistogram.h"
32 //#include "vtkJPEGReader.h"
33 #include "vtkImageData.h"
34 #include "vtkImageCast.h"
35 #include "vtkComputeHistogram2DOutliers.h"
44 // ----------------------------------------------------------------------------
45 // WX headers inclusion.
46 // For compilers that support precompilation, includes <wx/wx.h>.
47 // ----------------------------------------------------------------------------
54 //----------------------------------------------------------------------------
55 // Class implementation
56 //----------------------------------------------------------------------------
58 //IMPLEMENT_CLASS(pHistogram, wxObject)
60 //----------------------------------------------------------------------------
62 //----------------------------------------------------------------------------
63 pHistogram::pHistogram(std::string filePath)
66 points = vtkImageData::New();
72 pHistogram::pHistogram(vtkImageData* imageData)
74 points = vtkImageData::New();
79 vtkImageCast* cast= vtkImageCast::New();
80 cast->SetInput(imageData);
81 cast->SetOutputScalarTypeToInt();
85 buildHistogram(imageData);
88 //----------------------------------------------------------------------------
89 pHistogram::~pHistogram()
91 if(points!=NULL)points->Delete();
94 //----------------------------------------------------------------------------
95 void pHistogram::setImagePath(std::string filePath)
100 //----------------------------------------------------------------------------
101 void pHistogram::buildHistogram()
104 reader: is the reader of the image
105 histogramVector:Is the image data of the original image
106 imageData: vtkImageData of the image that we are reading
107 range :it has the (min/max) range of the levels of grey
109 points= vtkImageData::New();
110 vtkMetaImageReader *reader = vtkMetaImageReader::New();
111 vtkImageData* imageData=NULL;
115 reader->SetFileName(path.c_str());
120 imageData=reader->GetOutput();
121 imageData->GetScalarRange(range);
122 initializePoints(size);
123 setPoints(imageData);
127 Calculate the histogram and save it in the attribute points
128 it is used if the user had given the imageData
129 Pre: Size had to be setted if the user wants
130 another value that 100
132 void pHistogram::buildHistogram(vtkImageData* imageData)
134 initializePoints(size);
135 setPoints(imageData);
139 getting ready the points
141 void pHistogram::initializePoints(int xDimension)
143 //setting image data of the points
144 points->SetDimensions(xDimension,1,1);
145 //EED points->SetScalarTypeToUnsignedShort();
146 points->SetScalarTypeToDouble();
147 points->AllocateScalars();
152 constructing the histogram
154 void pHistogram::setPoints(vtkImageData* imageData)
157 printf("EED pHistogram::setPoints Trinng new histogram ..\n");
159 printf("EED pHistogram::setPoints Test: vtkPComputeHistogram2DOutliers\n");
160 vtkComputeHistogram2DOutliers *vtkhist = vtkComputeHistogram2DOutliers::New();
161 vtkhist->SetPreferredNumberOfOutliers(10);
162 vtkhist->SetInput(imageData);
163 vtkTable *resulttable = vtkhist->GetOutputTable();
165 printf("EED pHistogram::setPoints rows:%d\n", (int)(resulttable->GetNumberOfRows()) );
166 printf("EED pHistogram::setPoints colums:%d\n", (int)(resulttable->GetNumberOfColumns()) );
173 char* dataImagePointerC = (char*)imageData->GetScalarPointer(0,0,0);
174 unsigned char* dataImagePointerUC = (unsigned char*)imageData->GetScalarPointer(0,0,0);
175 short* dataImagePointerS = (short*)imageData->GetScalarPointer(0,0,0);
176 unsigned short* dataImagePointerUS = (unsigned short*)imageData->GetScalarPointer(0,0,0);
177 float* dataImagePointerF = (float*)imageData->GetScalarPointer(0,0,0);
178 double* dataImagePointerD = (double*)imageData->GetScalarPointer(0,0,0);
180 double* dataHistogramPointer = (double*)points->GetScalarPointer(0,0,0);
190 imageData->GetScalarRange(range);
194 Setting the minimun and maximum levels of grey
196 maxLevelOfGrey = range[1];
197 minLevelOfGrey = range[0];
198 //std::cout<<"maxLevelOfGrey "<<maxLevelOfGrey<<" minLevelOfGrey "<<minLevelOfGrey<<std::endl;
203 imageData->GetExtent(ext);
213 getting ready the histogram
217 dataHistogramPointer[i]=0;
223 if (imageData->GetScalarType()==VTK_CHAR)
225 for(i=0;i<sizeImage;i++)
227 j=getIndex(*dataImagePointerC);
229 dataHistogramPointer[j]++;
233 if (imageData->GetScalarType()==VTK_UNSIGNED_CHAR)
235 for(i=0;i<sizeImage;i++)
237 j=getIndex(*dataImagePointerUC);
238 dataImagePointerUC++;
239 dataHistogramPointer[j]++;
244 if (imageData->GetScalarType()==VTK_SHORT)
246 for(i=0;i<sizeImage;i++)
248 j=getIndex(*dataImagePointerS);
250 dataHistogramPointer[j]++;
254 if (imageData->GetScalarType()==VTK_UNSIGNED_SHORT)
256 for(i=0;i<sizeImage;i++)
258 j=getIndex(*dataImagePointerUS);
259 dataImagePointerUS++;
260 dataHistogramPointer[j]++;
265 if (imageData->GetScalarType()==VTK_FLOAT)
267 for(i=0;i<sizeImage;i++)
269 j=getIndex(*dataImagePointerF);
271 dataHistogramPointer[j]++;
276 if (imageData->GetScalarType()==VTK_DOUBLE)
278 for(i=0;i<sizeImage;i++)
280 j=getIndex(*dataImagePointerD);
282 dataHistogramPointer[j]++;
290 Returns the poins of the histograms
292 vtkImageData* pHistogram::getHistogram()
298 hash por getting the index for the histogram vector of the original
300 @gValue: Level of grey for which wants the index in the histogrram
302 int pHistogram::getIndex(double gValue)
305 double p=((double)gValue-minLevelOfGrey)/(maxLevelOfGrey-minLevelOfGrey);
307 //std::cout<<"gValue "<<gValue<<" k "<<k<<std::endl;
313 void pHistogram::setSize(int nSize)
320 int pHistogram::getImageSize()
325 Get Size of the histogram
327 int pHistogram::getSize()
332 Get the maximum value of grey of the histogram
334 int pHistogram::getMaximumLevelOfGrey()
336 return maxLevelOfGrey;
339 Get the minimum value of grey of the histogram
341 int pHistogram::getMinimumLevelOfGrey()
343 return minLevelOfGrey;
346 get a point of the Histogram
349 int pHistogram::getHistogramPoint(int gValue)
351 //double p=((float)gValue-minLevelOfGrey)/(maxLevelOfGrey-minLevelOfGrey); // JPRx
354 double* dataHistogramPointer = dataHistogramPointer=(double*)points->GetScalarPointer(0,0,0);
355 return dataHistogramPointer[gValue];