[Insight-users] Histogram modification - troubles with SetFrequency
Luis Ibanez
luis.ibanez at kitware.com
Thu Dec 3 21:39:43 EST 2009
Hi Sacrif,
A) The problem is probably that "pow()" is returning a double.
Please try replacing the expression:
histogram->SetFrequency(bin,
pow(histogram->GetFrequency(bin,0),2));
with the more explicit:
const float value = pow(histogram->GetFrequency(bin,0),2);
histogram->SetFrequency(bin,value);
B) In your second expression:
partialHistogramVector_[0]->SetFrequency(bin, value);
what is the type of the variable :
partialHistogramVector_
please post the declaration of its type.
C) If you use the New Statistics Framework, you will have
available the following method:
/** Set all the bins in the histogram to a specified frequency */
void SetFrequency( AbsoluteFrequencyType value );
/** Set the frequency of an instance identifier. Returns false if the bin is
* out of bounds. */
bool SetFrequency( InstanceIdentifier id, AbsoluteFrequencyType value);
/** Set the frequency of an index. Returns false if the bin is
* out of bounds. */
bool SetFrequency(const IndexType &index,
AbsoluteFrequencyType value);
/** Set the frequency of a measurement. Returns false if the bin is
* out of bounds. */
bool SetFrequency(const MeasurementVectorType &measurement,
AbsoluteFrequencyType value);
Note that in the New Statistics Framework, the type
AbsoluteFrequencyType is declared in the file
Insight/Code/Review/Statistics/
itkMeasurementVectorTraits.h
as
typedef size_t InstanceIdentifier;
/** Type defined for representing the frequency of
measurement vectors */
typedef InstanceIdentifier
AbsoluteFrequencyType;
which is intended to just "Count" elements the histogram bins.
this is therefore an "Integer" type. Not a float type as the FrequencyType
was in the old framework.
Should you need to compute relative frequencies, then you can use
in the New framework, the type RelativeFrequencyType.
Regards,
Luis
-------------------------------------------------------------------------------------------------
On Thu, Dec 3, 2009 at 3:12 AM, sacrif <markus_m at gmx.net> wrote:
>
> Hi Luis!
>
> Thank you for your reply.
> The program does not compile. The exact error message is:
>
> 1>Compiling...
> 2>AlphaHistogram.cpp
> 2>..\Alpha_Histogramm\AlphaHistogram.cpp(229) : error C2663:
> 'itk::Statistics::Histogram<TMeasurement>::SetFrequency' : 4 overloads have
> no legal conversion for 'this' pointer
> 2> with
> 2> [
> 2> TMeasurement=double
> 2> ]
>
>
> So if I take the "bool SetFrequency" method my arguments should be:
> 1. unsigned long identifier;
> 2. float value;
>
> So what I tried now is the following but the same error still occures:
> unsigned long bin = 1000;
> float value = 10;
> partialHistogramVector_[0]->SetFrequency(bin, value);
>
>
> When I use the new Statistics Framework, are there any changes for the
> creation of histograms(or are descriptions in ImageHistogram1-4.cxx and
> Histogram.cxx still valid) the and the use of the Set - GetFrequency
> methods?
>
> Regards Mark
>
>
> Luis Ibanez wrote:
>>
>> Hi Sacrif,
>>
>> In the old statistics framework,
>> the FrequencyType of the Histogram is defined as:
>>
>> typedef float FrequencyType;
>>
>> in the file
>>
>> Insight/Code/Numerics/Statistics/itkDenseFrequencyContainer.h
>>
>>
>>
>> When you say about the expression:
>>
>>
>>> histogram->SetFrequency(bin, pow(histogram->GetFrequency(bin,0),2)); //
>>> pow(x,2)
>>
>>
>> that:
>>
>> "It doesn't work"...
>>
>>
>> do you mean that:
>>
>> A) It doesn't compile ?
>>
>> B) It seg. faults at run time ?
>>
>> C) It throws an exception at run time ?
>>
>> D) It doesn't produce any errors, but the resulting
>> numerical value is not the expected one ?
>>
>>
>> Please be more specific,
>>
>>
>> Thanks
>>
>>
>> Luis
>>
>> ----------
>>
>> BTW: Please note that the Statistics Framework was fully
>> refactored and that the new version is under:
>>
>> Insight/Code/Review/Statistics
>>
>> we strongly encourage you to adopt this new version.
>>
>> In order to use it, you just need to reconfigure ITK with CMake
>> and turn ON the following two CMake variables:
>>
>> ITK_USE_REVIEW
>> ITK_USE_REVIEW_STATISTICS
>>
>>
>>
>>
>>
>> --------------------------------------------------------------------------------------------------------------
>> On Wed, Dec 2, 2009 at 3:34 PM, sacrif <markus_m at gmx.net> wrote:
>>>
>>> Hello,
>>>
>>> I am new to ITK and have troubles with the histogram->SetFrequency()
>>> method.
>>> What I did yet was to read in a 3d Analyse image (.hdr and .img format)
>>> using the filereader
>>> and the AnlayseImageIO class. Then I used the
>>> "itkScalarImageToHistogramGenerator.h" class to create a histogram out of
>>> the image I read in. So far everything worked well. However my next step
>>> is
>>> to modify the histogram. I want to exponentiate the frequency value of
>>> every
>>> bin by a certain number. I tried to do that with the following code.
>>>
>>> //-------------------------------------------
>>> typedef signed short PixelType;
>>> static const unsigned int Dimension = 3;
>>> typedef itk::Image<PixelType, Dimension> ImageType;
>>> typedef itk::Statistics::ScalarImageToHistogramGenerator< ImageType >
>>> HistogramGeneratorType;
>>> typedef HistogramGeneratorType::HistogramType HistogramType;
>>> ...
>>> const HistogramType * histogram = histogramGenerator->GetOutput();
>>> const unsigned int histogramSize = histogram->Size();
>>>
>>> unsigned int bin;
>>> for( bin=0; bin < histogramSize; bin++ )
>>> {
>>> histogram->SetFrequency(bin,
>>> pow(histogram->GetFrequency(bin,0),2)); //
>>> pow(x,2) just exponentitates x with 2.
>>> }
>>> //-------------------------------------------
>>>
>>> Unfortunately this does not work - obviously "unsigned int" is not the
>>> right
>>> type to asign.
>>> I also tried to define:
>>> HistogramType::IndexType index;
>>> index[0] = 1000; // just as an example
>>>
>>> and put "index" at the place of "bin"( histogram->SetFrequency(index,
>>> pow(histogram->GetFrequency(bin,0),2));), but it did not work.
>>> Could you please tell me what kind of arguments SetFrequency needs, or
>>> whether there is a better way to modify the histogram.
>>> (histogram->GetFrequency(bin, 0) works without any problems by the way)
>>>
>>> Kind Regards
>>> Mark
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Histogram-modification---troubles-with-SetFrequency-tp26615939p26615939.html
>>> Sent from the ITK - Users mailing list archive at Nabble.com.
>>>
>>> _____________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Kitware offers ITK Training Courses, for more information visit:
>>> http://www.kitware.com/products/protraining.html
>>>
>>> Please keep messages on-topic and check the ITK FAQ at:
>>> http://www.itk.org/Wiki/ITK_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.itk.org/mailman/listinfo/insight-users
>>>
>> _____________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Kitware offers ITK Training Courses, for more information visit:
>> http://www.kitware.com/products/protraining.html
>>
>> Please keep messages on-topic and check the ITK FAQ at:
>> http://www.itk.org/Wiki/ITK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.itk.org/mailman/listinfo/insight-users
>>
>>
>
> --
> View this message in context: http://old.nabble.com/Histogram-modification---troubles-with-SetFrequency-tp26615939p26621725.html
> Sent from the ITK - Users mailing list archive at Nabble.com.
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
More information about the Insight-users
mailing list