[Insight-users] Histogram modification - troubles with SetFrequency

sacrif markus_m at gmx.net
Thu Dec 31 07:30:14 EST 2009


Hello, thank you for your reply!

In the meanwhile I worked arround with an std::vector. However I now came to
a point where I need the itk histogram again. So I tried to copy the
histogram, but unfortunately there seem to be some problems.

What I did is I created a histogram using a histogram generator and now I
try to copy this const histogram into a not const histogram. My attemt to do
so is below:

typedef itk::Image<PixelType, Dimension> InputImageType;
typedef itk::Statistics::ScalarImageToHistogramGenerator< 
                                 InputImageType >   HistogramGeneratorType;
typedef HistogramGeneratorType::HistogramType  HistogramType;

...

const HistogramType * histogram1 = histogramGenerator->GetOutput();

HistogramType::Pointer testHist = HistogramType::New();

for(unsigned int i = 0; i < histogram1->Size(); i++)
{
    testHist->SetBinMin(0,i,histogram1->GetBinMin(0,i));
    testHist->SetBinMax(0,i,histogram1->GetBinMax(0,i));
    testHist->SetFrequency(i,histogram1->GetFrequency(i,0));
}  

This does unfortunately (and as I almost expected) not work(When I execute
the program I get the following message from the MS VC++ Debug Library:
Debug Assertion Failed ... Expression: vector subscript out of Range!).
However I can not find Methods for my testHist that allow to set the values
which I set for the histogramGenerator which created histogram1.
(Like ->SetNumberOfBins(), SetHistogramMin(), SetHistogramMax())
The only method that could help I found was testHist->Initialize(), which I
assume I have to call before the for loop above.

However I am not quite sure which values the method needs.
According to the description these are:
- const Histogram<...>::SizeType &size
and optionally:
- Histogram<...>::MeasurementVectorType &lowerBound
- Histogram<...>::MeasurementVectorType &upperBound

For now I only entered the first value:
- histogram1->Size()

When compiling this results in the following error:

1>..\Alpha_Histogramm\AlphaHistogram.cpp(288) : error C2664: 'void
itk::Statistics::Histogram<TMeasurement,VMeasurementVectorSize,TFrequencyContainer>::Initialize(const
itk::Size<VDimension> &)' : cannot convert parameter 1 from 'unsigned int'
to 'const itk::Size<VDimension> &'
1>        with
1>        [
1>            TMeasurement=double,
1>            VMeasurementVectorSize=1,
1>            TFrequencyContainer=itk::Statistics::DenseFrequencyContainer,
1>            VDimension=1
1>        ]
1>        and
1>        [
1>            VDimension=1
1>        ]
1>        Reason: cannot convert from 'unsigned int' to 'const
itk::Size<VDimension>'
1>        with
1>        [
1>            VDimension=1
1>        ]
1>        No constructor could take the source type, or constructor overload
resolution was ambiguous


So my Questions are:
- What values do I have to enter in the Initialize() method. Is it right
that the first value (const Histogram<...>::SizeType &size) stands for the
number of bins? Or does this size stand for something else.
- Are the other two optional values the intensity minimum and the intensity
maximum of the histogram? And which methods from the histogram which I want
to copy do I have to enter for these parameters.
- Is the generall approach of copying the histogram correct? Or did I miss
some further steps to make this work?


Thank you for your help!

Regards Sacrif










Luis Ibanez wrote:
> 
> Hi Sacrif,
> 
> Thanks for pointing this out.
> 
> This is indeed the case,  ITK filters own their output
> and they are the only ones that should change the
> output objects.
> 
> This is a requirement for good-behavior when the
> filters are put into a pipeline.
> 
> You are not supposed to modify the output of a
> filter.
> 
> In your case, you could create a new Histogram
> manually, and copy the computed elements
> from the output of the Histogram that you get from
> the generator.
> 
> Something similar to:
> 
> const HistogramType * histogram1 = histogramGenerator->GetOutput();
> 
> HistogramType::Pointer histogram2 = HistogramType::New();
> 
> // Add here:
> // Copy lower, upper values of bins
> // Copy values of numbers of bins
> // Allocate size for the new historgram2
> //
> 
> //
> //  Now copy the recomputed values
> //
> HistogramType::Iterator itr2 = historgram2->Begin();
> HistogramType::ConstIterator itr1 = histogram1->Begin();
> 
> while( itr1 != histogram1->End() )
>   {
>   *itr2 = pow(  *itr1, 2.0 )
>   ++itr1;
>   ++itr2;
>   }
> 
> 
>   Regards,
> 
> 
>         Luis
> 
> 
> --------------------------------------------------------------------------------
> On Fri, Dec 4, 2009 at 3:43 AM, sacrif <markus_m at gmx.net> wrote:
>>
>> Hi, I finally found out what the problem is. The histogram is defined as
>> const HistogramType * histogram; or HistogramType::ConstPointer
>> histogram;
>>
>> However the SetFrequency method is a not const method. Therefore non of
>> the
>> 4 SetFrequency methods is applicable on it.
>>
>> The problem is that the GetOutput() method of the
>> itk::Statistics::ScalarImageToHistogramGenerator class returns a "const
>> HistogramType *" which I assign to my "const HistogramType* histogram"
>> pointer. So I can only define the histogram as const. But then the
>> SetFrequency would not work. (and results in the compilation error: error
>> C2663: 'itk::Statistics::Histogram<TMeasurement>::SetFrequency' : 4
>> overloads have no legal conversion for 'this' pointer...<--as written in
>> my
>> previous post)
>>
>> Is it possible that a histogram as I defined it can't be changed as soon
>> as
>> it is created? Somehow I can't imagine this is the case. But at the
>> moment I
>> can only imagine to write the values in an std::vector to proceed working
>> on
>> it.
>> I would appreciate any onther advice.
>>
>> Thank you & kind regards
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Histogram-modification---troubles-with-SetFrequency-tp26615939p26635812.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-tp26615939p26977713.html
Sent from the ITK - Users mailing list archive at Nabble.com.



More information about the Insight-users mailing list