[Insight-developers] Fastest way to label an array
Nicolas RANNOU
nrannou at bwh.harvard.edu
Tue Jun 30 13:58:24 EDT 2009
Thank you very much I will try it
Yes this is quantizing.
Then I will just use itk::Functor::ScalarToRGBPixelFunctor and adapt it.
Yes X, Y and K are related. X and Y are arrays which contain the
boundaries for each label.
So something like that will be easier to understand but I first thought
that you didn't need all these informations :
For All Pixels in the 2D Image do:
Get the pixel intensity
For all K label values do:
If Intensity is > x[k] and Intensity is < y[k]
Set pixel label to value K
Thanks for your help,
Nicolas
On Tue, 30 Jun 2009 13:27:01 -0400, Luis Ibanez <luis.ibanez at kitware.com>
wrote:
> Hi Nicolas,
>
> Thanks for the clarification.
>
> 10 seconds for labelling a 300x300 pixels image
> seems to be indeed a very long time.
>
> It is still not clear to me what is the rule that
> you are using for labeling every individual pixel.
>
> From your first email it seems that your pseudo-code is
>
>
> For All Pixels in the 2D Image do:
>
> Get the pixel intensity
>
> For all K label values do:
>
> If Intensity is > x and Intensity is < y
> Set pixel label to value K
>
>
>
> How are X and Y related to K ?
> or are they supposed to be the position in space of
> the pixel ?
>
>
> It actually seems that you are simply quantizing the
> intensity levels of your image. If so, you could do
> this a lot easier with a UnaryFunctor filter, for which
> you create a functor with the ranges x,y,w,z....
>
> See for example what is done in
>
> Insight/Examples/Segmentation/WatershedSegmentation1.cxx
>
> with the
>
> itk::Functor::ScalarToRGBPixelFunctor
>
>
> You could write a class, similar to the ScalarToRGBPixelFunctor
> but, that instead of assigning mapped RGB color values, it will
> assign labels.
>
>
> Running such filter in an image of 300x300 pixels should take
> less that 0.1 seconds... (in a modern computer).
>
>
>
> Regards,
>
>
> Luis
>
>
>
>
------------------------------------------------------------------------------------------------
> On Tue, Jun 30, 2009 at 12:02 PM, Nicolas RANNOU
> <nrannou at bwh.harvard.edu>wrote:
>
>> Hi Luis,
>>
>> I'm working on an VTK image but I can convert it into ITK for
> processing.
>> My "array" is a 2D image, because if I process the whole volume, the
> time
>> of processing is too long (too many pixels to process through my loops).
>>
>>
>> I want to create the label map associated to this 2D image. But the time
> of
>> processing must be short (< 1 second), not depending (or just a little)
> on
>> the number of labels.
>> For example, now, the time of processing for a 300*300 array and 6
> labels
>> is up to 10 seconds!
>>
>> Which filter would you recommand to me for the conversion into itk ? I
>> usually use itkImageToVTKImageFilter and itkVTKImageToImageFilter but
> I'm
>> not sure that it is the "best".
>> (I need to get the result of the labelling as a vtkimagedata for
>> visualization)
>>
>> I will have a look at itkImageClassifierFilter to see if it can solve my
>> problem!
>>
>>
>> Thanks for your help,
>>
>>
>> Nicolas
>>
>> On Tue, 30 Jun 2009 11:37:18 -0400, Luis Ibanez
> <luis.ibanez at kitware.com>
>> wrote:
>> > Hi Nicolas,
>> >
>> > Could you please provide more context ?
>> >
>> > Are you doing this with ITK images ?
>> >
>> > Are you doing this with VTK images ?
>> >
>> >
>> > What you call an "array" is it really a 2D image ?
>> > or a 3D image ?
>> >
>> >
>> > The relationship between the "array" and the
>> > label map is not clearly described in your email.
>> >
>> >
>> > ...
>> >
>> > At first sight, you seem to be trying to rewrite the
>> > functionalities of the itkImageClassifierFilter...
>> >
>> >
>> >
>> > Thanks for any clarifications,
>> >
>> >
>> > Luis
>> >
>> >
>> > ----------------------------------------------------
>> > On Mon, Jun 29, 2009 at 1:08 PM, Nicolas Rannou
>> > <nrannou at bwh.harvard.edu>wrote:
>> >
>> >> Hi all,
>> >>
>> >> I'm currently trying to process an array, to create a label map
>> > associated
>> >> to this array.
>> >> The problem is that I want a fast processing and the method I use is
> too
>> >> slow.
>> >>
>> >> What I do:
>> >>
>> >> /------------------------------------------------------------/
>> >> for(i...){ // 2 for loops to go through the array
>> >> for(j...){
>> >> for(int k;k=0;k<nbOfLabels){ // A loop to test the value of the
> pixel
>> > to
>> >> know to which label associate it
>> >> if(ArrayToCreateTheLabelMap->GetScalarComponentAsDouble(i,j,...)
>> x
>> > &&
>> >> ArrayToCreateTheLabelMap->GetScalarComponentAsDouble(i,j,...) < y){
>> >> ArrayLabelMap->SetScalarComponentFromDouble(i,j) = k; //fill the
>> > label
>> >> map
>> >> }
>> >> }
>> >> }
>> >> }
>> >> /----------------------------------------------------------/
>> >> Do you have any suggestion to increase the time of processing?
>> >> Maybe should I use something else than Get/SetScalarComponent.
>> >> Is it possible to do a fast mapping, to say that all pixels (in the
>> > array
>> >> or in a volume) between x and y should be egal to 1, between w and z
>> > egal to
>> >> 2... instead of doing these loops?
>> >> With 2 labels, the time of processing is ok but as soon as the number
> of
>> >> label increases, it becomes too long.
>> >>
>> >> Thanks,
>> >>
>> >> Nicolas
>> >> _______________________________________________
>> >> Powered by www.kitware.com
>> >>
>> >> Visit other Kitware open-source projects at
>> >> http://www.kitware.com/opensource/opensource.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-developers
>> >>
>>
>>
More information about the Insight-developers
mailing list