[Insight-users] logarithmic intensity transformation

Zachary Pincus zpincus at stanford.edu
Wed Jun 29 12:59:49 EDT 2005


This is just a side note, but I think that in general learning to use  
ITK's iterators properly is a much better use of time than trying to  
deal with raw chunks of pixels in memory. The first time you have to  
iterate only over some sub-region of the image, or need to iterate over  
an image and consult the neighbors of a pixel, or need easy access to  
the pixel's coordinates, or any number of tasks, you'd need to write  
and debug a fair bit of (tricky and uninteresting) code that ITK   
*already has*, already has working for arbitrary n-dimensional images,  
and already has working fast.

And, really, is using an iterator too different than accessing data  
from an array in a for loop? The whole point of STL iterators is that  
they are a generalization of pointers to data in arrays, so the access  
paradigm is very similar. Check it out:

// Nasty and slow, using indices.
ImageType::Pointer image = whatever...
image->GetPixelContainer()->SetContainerManageMemory(false);
PixelType * CArray = image->GetPixelContainer()->GetImportPointer();
for (int i = 0; i < image->GetPixelContainer()->Size(); i++) {
   PixelType p = CArray[i];
}

// Using a pointer as a primitive "iterator". Fast but still nasty.
ImageType::Pointer image = whatever...
image->GetPixelContainer()->SetContainerManageMemory(false);
PixelType * CArray = image->GetPixelContainer()->GetImportPointer();
for (PixelType *i = Carray; i !=  
Carray[image->GetPixelContainer()->Size()]; i++) {
   PixelType p = *i;
}

// using itk iterators. Fast and beautiful.
ImageType::Pointer image = whatever...
ImageRegionIterator<ImageType> iter(image,  
image->GetLargestPossibleRegion());
for (iter.GoToBegin(); !iter.IsAtEnd(); ++iter) {
   PixelType p = iter.Get();
}

Zach Pincus

Department of Biochemistry and Program in Biomedical Informatics
Stanford University School of Medicine

On Jun 29, 2005, at 5:58 AM, Renaud Isabelle wrote:

> Hi,
>  
> I already knew about GetPixel() and SetPixel() methods as well as  
> iterators to access the value of one pixel of my image.
>  
> But is there already a method which enables me to retrieve the pixel  
> data of my image directly in one matrix, such as GetBuffer or  
> something like that? Maybe this is not the ideal but I was more  
> familiar with having data stocked in one matrix and accessing pixel  
> data via for loop and  so on....
>  
> Isabelle
>
> Jakub Bican <jakub.bican at matfyz.cz> a écrit :
>>
>>
>> Hi Isabelle
>>
>> How to access the pixel data is described in the ITK Software Guide
>>
>> http://www.itk.org/ItkSoftwareGuide.pdf
>>
>> Look for the chapter 4.1.3 "Accessing Pixel Data" (page 38).
>>
>> You can also use more efficient way - iterators. See chapter 11
>> "Iterators" (page 687).
>>
>> Regards,
>> Jakub.
>>
>>
>>
>> Renaud Isabelle napsal(a):
>> > Hi Jakub,
>> >
>> > I took a look on your filter. However, I think there was a
>> > misunderstanding.
>> >
>> > I don't want to perform a pixel-wise log operation on my image.
>> >
>> > Actually, I want to perform a kind of histogram transform called
>> > *histogram logarithmic* to improve the contrast of my image.
>> >
>> > So far, I performed histogram usual rescaling to transform my
>> > intensities into the interval 0-255. Now, I would like my  
>> distribution
>> > of gray intensities would be adjusted to improve contrast like:
>> >
>> > f`'(x,y) = f min * (fmax / fmin) * P(f(x,y)) where P is the  
>> cumulated
>> > histogram.
>> >
>> > So adaptor will not help me, because this is an overall transform  
>> of the
>> > image. Maybe I have to create my own filter but how can I access the
>> > matrice of my pixel data form my image?
>> >
>> > thanks,
>> >
>> > Isabelle
>> >
>> >
>> > */Jakub Bican /* a écrit :
>> >
>> >
>> > Hi Isabelle,
>> >
>> > logarithmic scaling can be done by these filters:
>> >
>> > LogImageFilter (
>> > http://www.itk.org/Doxygen/html/classitk_1_1LogImageFilter.html )
>> > Log10ImageFilter (
>> > http://www.itk.org/Doxygen/html/classitk_1_1Log10ImageFilter.html )
>> >
>> > and/or adaptors:
>> >
>> > LogImageAdaptor (
>> > http://www.itk.org/Doxygen/html/classitk_1_1LogImageAdaptor.html )
>> !  > Log10ImageAdaptor (
>> > http://www.itk.org/Doxygen/html/classitk_1_1Log10ImageAdaptor.html )
>> >
>> > Hope this will help you.
>> >
>> > Regards,
>> > Jakub
>> >
>> >
>> > Renaud Isabelle napsal(a):
>> >
>> > > Hi Luis,
>> > >
>> > > In one of your numerous posted replies, you already mentioned the
>> > use
>> > > of *logarithmic scaling* to improve visualisation of images.
>> > >
>> > > "It is not rare to use a logarithmic intensity transformation in
>> > order
>> > > to display the FFT output and still be able to "see" something."
>> > >
>> >  
>> http://public.kitware.com/pipermail/insight-users/2004-November/ 
>> 011201.html
>> > >
>> > > This is actually what I need to do to improve the quality of my
>> > > ultrasonographic image.
>> > >
>> > > --> Could you tell me a way to perform this logarithmic scaling?  
>> Is
>> > > there already a function for t! hat, or maybe could I compute my
>> > own one
>> > > if you tell me how to get access of the pixel data of my image
>> > > displayed with ITK and VTK.
>> > >
>> > > Thanks for answer,
>> > >
>> > > Isabelle
>> > >
>> > >
>> >  
>> ---------------------------------------------------------------------- 
>> --
>> > > *Appel audio GRATUIT partout dans le monde* avec le nouveau Yahoo!
>> > > Messenger
>> > > Téléchargez le ici !
>> > >
>> > >
>> > >
>> >  
>> >--------------------------------------------------------------------- 
>> ---
>> > >
>> > >_______________________________________________
>> > >Insight-users mailing list
>> > >Insight-users at itk.org
>> > >http://www.itk.org/mailman/listinfo/insight-users
> Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo!  
> Messenger
> Téléchargez le ici ! _______________________________________________
> 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