[Insight-users] Getting unknown amount random Pixels
Luis Ibanez
luis.ibanez at kitware.com
Mon Sep 13 15:30:02 EDT 2004
Hi Neilson,
Yes, that's my mistake, itkSetMacro() and itkGetMacro()
should only be used in classes deriving from itk::Object.
Please write the full Get/Set methods as
PixelType GetThreshold() const
{ return m_Threshold; }
void SetThreshold( PixelType value )
{ m_Threshold = value; }
Sorry about that,
Regards,
Luis
-------------------------------
N.E. Mackenzie Mackay wrote:
> Hey Luis,
>
> Thanks for the help. This certainly helps.
>
> One question. When trying to compile itkSetMacro( Threshold,
> PixelType ) and itkGetMacro( Threshold, PixelType ) I get a error:
>
> " 'GetDebug': is not a member of
> 'ImageRandomConditionalIteratorWithIndex<class itk::Image<float,3>' "
>
> I am assuming this because the GetDebug method is in itkObject.h
> which is not inherited by ImageRandomConditionalIteratorWithIndex.
> What would you recommend in getting around this problem?
>
> Thank you again,
> Neilson
> On Sep 12, 2004, at 5:19 PM, Luis Ibanez wrote:
>
>>
>>
>> Hi Neilson,
>>
>>
>> You can easily overcome this difficulty by taking the code of the
>> Iterator, renaming the class and adding to it the functionality
>> you need for evaluating the threshold.
>>
>>
>> Please do the following:
>>
>>
>> 1) Take the files
>>
>>
>> Insight/Code/Common
>>
>> itkImageRandomConstIteratorWithIndex.h
>> itkImageRandomConstIteratorWithIndex.txx
>>
>> and rename them as
>>
>> itkImageRandomConditionalConstIteratorWithIndex.h
>> itkImageRandomConditionalConstIteratorWithIndex.txx
>>
>>
>>
>>
>> 2) Edit both new files and replace all occurrences of the string
>>
>> ImageRandomConstIteratorWithIndex
>>
>> with
>>
>> ImageRandomConditionalConstIteratorWithIndex
>>
>>
>>
>>
>>
>> 3) At the end of the header file (extension .h) just below the line
>>
>> unsigned long m_NumberOfPixelsInRegion;
>>
>> add a new member variable
>>
>> IndexType m_Threshold;
>>
>>
>> 4) In the current method Operator++()
>>
>> Self & operator++()
>> {
>> this->RandomJump();
>> m_NumberOfSamplesDone++;
>> return *this;
>> }
>>
>> add the following the condition for checking the
>> pixel value against the threshold
>>
>> Self & operator++()
>> {
>> do {
>> this->RandomJump();
>> } while( this->Get() < m_Threshold );
>> m_NumberOfSamplesDone++;
>> return *this;
>> }
>>
>>
>>
>> With this change, every time to increment the iterator, it will
>> keep picking random samples until it finds one with value
>> above the threshold that you set.
>>
>> NOTE This may take significant time if the pixels with values
>> over the threshold are not very abundant in your image.
>>
>>
>>
>> 5) Add the Set/Get methods for the Threshold by
>> inserting lines
>>
>>
>> itkSetMacro( Threshold, PixelType );
>> itkGetMacro( Threshold, PixelType );
>>
>>
>>
>> 6) Then in your code instantiate this new Iterator
>>
>>
>> typedef ImageRandomConditionalConstIreratorWithIndex<ImageType>
>> RandomIterator;
>>
>> RandomIterator randIter( M_FixedImage, this->GetFixedImageRegion());
>>
>> randIter.SetNumberOfSamples( TheNumberOfSamplesThatIReallyWantToGet );
>>
>> randIter.SetThreshold( ThisIsMyThresholdForSelectingPixels );
>>
>> randIter.GoToBegin();
>>
>> // this is just in case you want to put them in an array....
>> std::vector<PixelType> myRandomPixelValuesOverThreshold;
>>
>> do {
>> ++randIter;
>> myRandomPixelValuesOverThreshold.push_back( randIter.Get() );
>> } while( !randIter.IsAtEnd() );
>>
>>
>> // At this point, the STL::Vector container has a list of //
>> grayscale values selected from randomly distributed
>> // pixels, all of which have values over the threshold.
>>
>>
>>
>>
>> You should read the Chapter on Image
>> Iterators from the ITK Software Guide.
>>
>>
>> http://www.itk.org/ItkSoftwareGuide.pdf
>>
>>
>>
>>
>>
>>
>> Regards,
>>
>>
>>
>> Luis
>>
>>
>> ----------------------------
>>
>>> ----------------------------------------------------------------------
>>> --
>>>
>>> Hi,
>>>
>>> I am currently trying to get a set of N number of Pixels in a
>>> image in random locations over a set threshold. I was attempting to
>>> use ImageRandomConstIteratorWithIndex but have come to realize that
>>> you need to set the number of samples you will be using before
>>> starting the iterator. My problems is I don't know how many pixels
>>> I need to sample before getting N pixels over the threshold.
>>>
>>> Here is my code:
>>>
>>> typedef ImageRandomConstIreratorWithIndex<ImageType> RandomIterator;
>>> RandomIterator randIter( M_FixedImage, this->GetFixedImageRegion())
>>>
>>> randIter.SetNumberOfSamples( m_NumberOfSpatialSamples );
>>> randIter.GoToBegin();
>>>
>>> RandomIterator ::PixelType pixelValue;
>>>
>>> for(int i = 0; i< N; i++)
>>> {
>>> pixelValue = randIter.Get();
>>>
>>> while(PixelValue == 0)
>>> {
>>> ++randIter;
>>> pixelValue = randIter.Get();
>>> }
>>> printf("pixel value = %e \n", pixelValue);
>>>
>>> container[i] = pixelValue;
>>> }
>>>
>>> The stuff that is printed to the screen is something like 8.61e-304
>>>
>>> Even when I simply try to use "get" some strange number comes out.
>>> Is it because get doesn't return a float or double but a object of
>>> some kind of container?
>>>
>>> Neilson
>>>
>>>
>>> ----------------------------------------------------------------------
>>> --
>>
>>
>>
>>
>>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>
More information about the Insight-users
mailing list