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"
43 // ----------------------------------------------------------------------------
44 // WX headers inclusion.
45 // For compilers that support precompilation, includes <wx/wx.h>.
46 // ----------------------------------------------------------------------------
53 //----------------------------------------------------------------------------
54 // Class implementation
55 //----------------------------------------------------------------------------
57 //IMPLEMENT_CLASS(pHistogram, wxObject)
59 //----------------------------------------------------------------------------
61 //----------------------------------------------------------------------------
62 pHistogram::pHistogram(std::string filePath)
65 points= vtkImageData::New();
71 pHistogram::pHistogram(vtkImageData* imageData)
73 points= vtkImageData::New();
78 vtkImageCast* cast= vtkImageCast::New();
79 cast->SetInput(imageData);
80 cast->SetOutputScalarTypeToInt();
84 buildHistogram(imageData);
87 pHistogram::~pHistogram()
89 if(points!=NULL)points->Delete();
91 //----------------------------------------------------------------------------
93 //----------------------------------------------------------------------------
95 void pHistogram::setImagePath(std::string filePath)
100 void pHistogram::buildHistogram()
103 reader: is the reader of the image
104 histogramVector:Is the image data of the original image
105 imageData: vtkImageData of the image that we are reading
106 range :it has the (min/max) range of the levels of grey
108 points= vtkImageData::New();
109 vtkMetaImageReader *reader = vtkMetaImageReader::New();
110 vtkImageData* imageData=NULL;
114 reader->SetFileName(path.c_str());
119 imageData=reader->GetOutput();
120 imageData->GetScalarRange(range);
121 initializePoints(size);
122 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 points->SetScalarTypeToUnsignedShort();
146 points->AllocateScalars();
151 constructing the histogram
153 void pHistogram::setPoints(vtkImageData* imageData)
158 unsigned short* dataImagePointer=NULL;
159 unsigned short* dataHistogramPointer=NULL;
161 dataImagePointer=(unsigned short*)imageData->GetScalarPointer(0,0,0);
162 dataHistogramPointer=(unsigned short*)points->GetScalarPointer(0,0,0);
171 imageData->GetScalarRange(range);
173 Setting the minimun and maximum levels of grey
175 maxLevelOfGrey=(int)range[1];
176 minLevelOfGrey=(int)range[0];
177 //std::cout<<"maxLevelOfGrey "<<maxLevelOfGrey<<" minLevelOfGrey "<<minLevelOfGrey<<std::endl;
182 imageData->GetExtent(ext);
192 getting ready the histogram
196 dataHistogramPointer[i]=0;
200 Constructing the Histogram
202 //int k=size/(maxLevelOfGrey-minLevelOfGrey);
204 for(i=0;i<sizeImage;i++)
207 hashing the histogram
209 //double p=((float)*dataImagePointer-minLevelOfGrey);
212 j=getIndex(*dataImagePointer);
213 //std::cout<<j<<std::endl;
214 dataHistogramPointer[j]++;
224 k=dataHistogramPointer[i];
229 Returns the poins of the histograms
231 vtkImageData* pHistogram::getHistogram()
237 hash por getting the index for the histogram vector of the original
239 @gValue: Level of grey for which wants the index in the histogrram
241 int pHistogram::getIndex(int gValue)
244 double p=((double)gValue-minLevelOfGrey)/(maxLevelOfGrey-minLevelOfGrey);
246 //std::cout<<"gValue "<<gValue<<" k "<<k<<std::endl;
252 void pHistogram::setSize(int nSize)
259 int pHistogram::getImageSize()
264 Get Size of the histogram
266 int pHistogram::getSize()
271 Get the maximum value of grey of the histogram
273 int pHistogram::getMaximumLevelOfGrey()
275 return maxLevelOfGrey;
278 Get the minimum value of grey of the histogram
280 int pHistogram::getMinimumLevelOfGrey()
282 return minLevelOfGrey;
285 get a point of the Histogram
288 int pHistogram::getHistogramPoint(int gValue)
290 //double p=((float)gValue-minLevelOfGrey)/(maxLevelOfGrey-minLevelOfGrey); // JPRx
293 unsigned short* dataHistogramPointer=NULL;
294 dataHistogramPointer=(unsigned short*)points->GetScalarPointer(0,0,0);
296 return dataHistogramPointer[gValue];