[Insight-users] Still struggling with implementing grayscale morphological operators

Luis Ibanez luis.ibanez at kitware.com
Wed Jul 29 15:12:12 EDT 2009


Hi Harvey,

Thanks for you additional clarification.


The Bad News:

The reason why you are having trouble finding a way of assigning
graylevel values to the structuring element is that...   this funcitonality
is not available.



The Good News:

Please find attached a modified version of the Shaped iterator that
now provides such functionality.

The additional API is:

      SetPixelWeight( i, value )
      GetPixelWeight( i )

The types are the same as the pixel type of the image.

The numeral "i" matches the same offsets that you have
activated in order to create the Shape of the iterator.

Also, for your convenience, we have attached here a
skeleton (compiling, but not functional yet) of a filter
that should get you started with implementing the Hit
or Miss filter.

Attached is also a minimal example of usage for that
filter.

Please note that this is just to help you get started.

We are not claiming that any of these classes are
ready for prime-time, but we hope that they will save
you a lot of time.


Please let us know if you have any questions,


      Thanks,


              Luis



------------------------------------------------------------------------------
On Wed, Jul 29, 2009 at 12:56 PM, Neal R. Harvey <harve at lanl.gov> wrote:

> Luis Ibanez wrote:
>
>>
>> Hi Harvey,
>>
>> Thanks for the clarification.
>>
>>      Let's go back to the basics then.
>>
>> It seems that you are interested in writing
>> a Grayscale morphological filter where the
>> structuring element has:
>>
>>          A) Arbitrary shape, and
>>          B) Values assigned to its own pixels.
>>
>> If that's the case,
>> then the major ITK elements that you need are:
>>
>> 1) itk::ShapedNeighborhoodIterator
>> 2) itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator
>>
>> You will find examples on these classes at:
>>
>> Insight/Examples/
>> ShapedNeighborhoodIterators1.cxx
>> ShapedNeighborhoodIterators2.cxx
>>
>   These are the examples in the book, right. As I said previously, I have
> read through these
>   but have been unable to determine exactly how to assign grayscale values
> to a neigborhood
>   iterator, as these examples do not show how to do this. They only show
> how to use pre-defined
>   kernels (such as for the Sobel and Gaussian: NeighborhoodIterators4.cxx
> and
>   NeighborhoodIterators3.cxx) or how to implement Binary Morphological
> operators
>   (ShapedNeighborhoodIterators1.cxx and ShapedNeighborhoodIterators2.cxx)
> which, by definition,
>   do not have any grayscale values, and are therefore not much help.
>
>  The rule of "hit" or "miss" will have to be implemented in
>> the inner loop where each one of the pixels in the neighbor
>> is visited.
>>
>   OK, but that supposes I know how to define the grayscale structuring
> element's values, which I don't.
>
>  This will be a great filter to contribute to the Insight Journal  :-)
>>
>   I would love to be in that position. However, I think I am quite some way
> away from that at the moment.
>
>   Thanks for your help and suggestions, though.
>
>  Please let us know if you have any questions regarding
>> the details of the implementation.
>>
>>
>>      Thanks
>>
>>
>>            Luis
>>
>>
>> ---------------------------------------------------------------------
>> On Wed, Jul 29, 2009 at 12:30 PM, Neal R. Harvey <harve at lanl.gov <mailto:
>> harve at lanl.gov>> wrote:
>>
>>    Luis Ibanez wrote:
>>
>>
>>        Hi Harvey,
>>
>>        For your convenience, we just added an example on the use of
>>        the GrayscaleFunctionDilateImageFilter to:
>>
>>        Insight/Examples/Filtering/GrayscaleFunctionDilateImageFilter.cxx
>>
>>        Please also find it attached to this email.
>>
>>
>>        The code is quite straight forward:
>>
>>         * read an image
>>         * instantiate filter
>>         * create structuring element
>>         * connect pipeline : reader, filter, writer
>>         * run
>>
>>
>>        Please give it  try and let us know if you have any questions.
>>
>>      Luis.
>>
>>      Thanks for this. However, this isn't solving the problem that I
>>    have.
>>      I want to create a very specific structuring element, where I
>>    have control
>>      over what grayscale values are in each position of the
>>    structuring element,
>>      and can define, within the overall envelope of the structuring
>>    element, what
>>      positions are within and outwith the structuring element's
>>    region of support.
>>
>>      For example, I may want to implement a grayscale hit-or-miss
>>    algorithm, in
>>      which the "hit" and "miss" structuring elements are actual
>>    images of targets
>>      and background. Say I am looking for a tank and I have an image
>>    of a tank
>>      which I am going to use for the "hit" and "miss" structuring
>>    elements.
>>      I only want the foreground (i.e. "hit") structuring element to
>>    be defined
>>      where the actual tank pixels are located and I want the
>>    grayscale values of
>>      this structuring element to be the same as the grayscale values
>>    of the actual
>>      tank pixels in the image. Similarly, for the background (i.e.
>>    "miss") structuring
>>      element, I only want this structuring element to be defined
>>    where there are
>>      no actual tank pixels and I want the grayscale values of this
>>    structuring element
>>      to be the same as the grayscale values of the actual background
>>    (i.e. non-tank)
>>      pixels in the image
>>
>>      Thus, having a pre-defined "ball" structuring element is not
>>    much help, certainly
>>      in the example describe above. Obviously, there are certain
>>    situations where
>>      a ball structuring element will be useful. However, one of the
>>    strengths of
>>      mathematical morphology is its ability to probe an image with a
>>    structuring element
>>      that has both spatial and "grayscale" extent and the ability to
>>    tailor the spatial and
>>      grayscale values of the structuring element to meet your
>>    particular needs.
>>        If you know of a way that I can do this, any information in
>>    this regard would be
>>      very much appreciated.
>>
>>      Thanks again and kindest regards
>>
>>      Harve
>>
>>
>>
>>           Thanks
>>
>>
>>                Luis
>>
>>
>>
>>
>>  ---------------------------------------------------------------------------------------
>>
>>
>>        On Tue, Jul 28, 2009 at 6:40 PM, Neal R. Harvey
>>        <harve at lanl.gov <mailto:harve at lanl.gov> <mailto:harve at lanl.gov
>>
>>        <mailto:harve at lanl.gov>>> wrote:
>>
>>           I am still struggling to implement grayscale morphological
>>        operators.
>>           The basic functions have been written:
>>           e.g.
>>
>> http://www.itk.org/Doxygen310/html/classitk_1_1GrayscaleFunctionDilateImageFilter.html
>>           Unfortunately there are no nice papers or tutorials, or
>>        even test
>>           code to provide insight as to exactly
>>           how to go about using them.
>>
>>           It appears that they use a neighborhood kernel and I
>>        haven't been
>>           able to figure out how to create a
>>           grayscale kernel. I have gone through the book - the part that
>>           describes neighborhood iterators, but
>>           so far that hasn't been a great deal of help. The examples they
>>           provide don't exactly show how to
>>           assign "grayscale" values to your kernel neighborhood iterator.
>>           The examples are for sobel and gaussian
>>           kernels, where there is code in the background that
>>        calculates the
>>           values for you. You never see the details
>>           of how it is used. The other examples they show in the book are
>>           for binary morphology, but that doesn't
>>           require graylevel values kernels, so also isn't much use.
>>
>>           Basically, I think I need to be able to read in an input image
>>           that is to be processed and two images that
>>           define the grayscale structuring element (SE), and output a
>>           processed image. One of the SE images
>>           defines the region of support of the SE (i.e. anywhere
>>        where the
>>           values are greater than 0 are in the
>>           SE's region of support). The other SE image defines the
>>        grayscale
>>           values in the SE. I then have to use
>>           these two SE images to create a suitable kernel.
>>
>>           Below is the code that I have written so far, in attempting to
>>           write my own Grayscale Morphological
>>           Operator based on the examples provided in the book. As you can
>>           see, it's not working and I am not
>>           sure how to solve that problem.
>>
>>           If anyone has any suggestions or ideas of how to get this
>>        working,
>>           or where to look to get information
>>           that could lead in that direction, it would be very much
>>        appreciated.
>>
>>           Kindest regards
>>
>>           Harve
>>
>>
>>           _____________________________________
>>           Powered by www.kitware.com <http://www.kitware.com>
>>        <http://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-users
>>
>>
>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090729/46370030/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: HitOrMissDraft.tgz
Type: application/x-gzip
Size: 4615 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090729/46370030/attachment-0001.bin>


More information about the Insight-users mailing list