Kernels used by LineJunctions

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
alosca
Posts: 52
Joined: 2010-03-04T17:54:57-07:00
Authentication code: 8675308
Location: Pasadena, California

Kernels used by LineJunctions

Post by alosca »

It says on IM Usage page (Morphology of Shapes) that

The default 'LineJunctions' kernel set only uses the first two junction definitions (the 'Y' and diagonal 'T' junctions), in the following way...
'LineJunctions:1@ ; LineJunctions:2>'


I created this kernel set for LineJunctions using kernel2image and got the following:

Image

They are the T's and Y's above but it seems when I run a hit-or-misss transform on the fabricated image below (scaled for illustration) it uses an aditional 3x3 kernel not shown above - check the 3x3 kernel centered on the little white disk. I think the result is correct and in fact I think there are many more line junction kernels beyond T's and Y's that one needs to account for when detecting junctions. Which ones IM actually use? Can I print (kernel2image) all of them?

Image

Also, does 'LineJunctions' work for 4-connected lines? I only tested on 8-connected lines.

Cheers,
- Alex.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Kernels used by LineJunctions

Post by anthony »

I ran the kernel2image command...
kernel2image -m -40.2 'LineJunctions' image.ong

and basically got the images expected.. 12 images in the correct order
first all 8 'Y' junction rotations (45 degree rotates), then all 4 the T junctions (90 degree rotates)
The image you show has all these, but the order seems randomized.

But for hit and miss order should not matter as any match to any kernel should appear in the results.

The result from what I can see is CORRECT.

The reason the corner matched is because of 'edge' virtual pixels. that is how IM was told to see pixels beyond the edge of the real image.
Edge is the default setting for virtual pixels. See
http://www.imagemagick.org/Usage/misc/#edge

The default 'line junction' set is for 8-connected junctions. Your image has no 4-connected junctions. However you can work out a 4 connected set...

Hmmm, that would be a and a 90 degree rotates orthogonal T

Code: Select all

   'LineJunctions:5;LineJunctions:3>'
However as the cross is included in ANY 'orthogonal 'T' it devolves to simply

Code: Select all

   'LineJunctions:3>'
I have updated the documentation in IM examples for Line Junction Kernels (give it a couple of hours to appear.
http://www.imagemagick.org/Usage/morpho ... ejunctions
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
alosca
Posts: 52
Joined: 2010-03-04T17:54:57-07:00
Authentication code: 8675308
Location: Pasadena, California

Re: Kernels used by LineJunctions

Post by alosca »

Thanks for responding. Indeed, the results are always correct. I was just wondering what kernels are actually used in LineJunctions given that the 3x3 kernel centered at the small white disk on the red pixel in the picture above is neither a T nor a Y in any rotation. As far as I understand a HMT would not assign this as a junction if only T's and Y's are considered. So you probably have other kernerls beyond these to report the solution shown above (red pixels).

The kernel centered at the small disk is

101
010
110

I have ran into other similar cases where it is clear T's and Y's were not sufficient to detect the reported line junctions

Thanks,
- Alex.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Kernels used by LineJunctions

Post by anthony »

The red pixel with a asterix in it, is both a diagonal T and a Y shape! It actually has two 'hits'

The kernels do not look for background pixels at all (they are transparent, not black). So both of these kernels will fit

100
010
101

and

100
011
100

NOTE 0 here is 'any pixel value' not 'background' The above doesn't format right using the proper '-' character
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
alosca
Posts: 52
Joined: 2010-03-04T17:54:57-07:00
Authentication code: 8675308
Location: Pasadena, California

Re: Kernels used by LineJunctions

Post by alosca »

Haha, I was taking the '0's to be background. Impressive that any combination of Y's and T's would produce the right junctions.
Thanks for the clarifications.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Kernels used by LineJunctions

Post by anthony »

Morphology has a proper neighbourhood definition (which convolve now also has)

A kernel value of NAN (floating point value of not-a-number) which is often set using a '-' on its own in defining a kernel, means "skip this kernel entry" when processing the kernel at each location. that means odd neighbourhoods are easy to handle.

The kernel2image converts this to transparency, but if you save as a JPG (which does not understand transparency) it comes out as black.

See IM Examples. User Defined Kernels
http://www.imagemagick.org/Usage/morphology/#user

As I mentions convolve traditionally does not have a neighbourhood, nor does it typically have kernels which are not odd sized squares or even kernels that are off centered,. IM allows you to convolve any of this... non-square, off-centered, and even odd neighbourhoods.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
alosca
Posts: 52
Joined: 2010-03-04T17:54:57-07:00
Authentication code: 8675308
Location: Pasadena, California

Re: Kernels used by LineJunctions

Post by alosca »

Very sophisticated! Thanks for the information. The line junction detection is working well.
Post Reply