Detection of x-axis and y-axis on a diagram

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
acidrous
Posts: 2
Joined: 2012-01-15T10:22:24-07:00
Authentication code: 8675308

Detection of x-axis and y-axis on a diagram

Post by acidrous »

I need to detect the x-axis and y-axis of a diagram and made those lines thicker. As you will see in the example image, this diagram might have axises on both sides which makes 4-lines to be processed. I am new to IM and have no idea where to start to accomplish this task.

An example of the diagram style that I am working on is given below. For now I am working on command-line of IM in windows environment. Thank you for your replies. (imagemagick v6.7.4-Q16)

Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Detection of x-axis and y-axis on a diagram

Post by fmw42 »

The only thing that I can think of to do that would be for you to manually measure the end points of the four lines and then use -draw to draw thicker lines using those coordinates. Most other image processing operations would likely make everything thicker.

see
http://www.imagemagick.org/Usage/draw/

Was your image converted from some vector format such as svg? If so you can go back to the vector format and modify the vector thickness for each of those four lines.
acidrous
Posts: 2
Joined: 2012-01-15T10:22:24-07:00
Authentication code: 8675308

Re: Detection of x-axis and y-axis on a diagram

Post by acidrous »

Thanks for the quick reply! This means that there is no auto-detection of the axises? Unfortunately, original images are in either .jpg or .gif format.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Detection of x-axis and y-axis on a diagram

Post by fmw42 »

You could try some X and Y edge detection and morphology to isolate the edges and then thicken them. But IM does not have anything like a Hough transform to locate the edges and extract the end points (as far as I know).

see
http://www.imagemagick.org/Usage/convolve/#edgedet
http://www.imagemagick.org/Usage/morphology/
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: Detection of x-axis and y-axis on a diagram

Post by whugemann »

I think this should work if you search for the crosses in the edges of the frame which exist only four times in the image. If you cut the image to quarters and then search for the cross via Compare, the textual output should provide the right coordinates. With these coordinates you could just draw thicker lines onto the image to get thicker axes.

It would be even easier if the axes would lie at the same location for each diagramm, but I suppose it's not that easy (?).

However, on my Windows computer, I cannot convince Compare to do its job on images which are not off the same size. I tried the code suggested by Fred somewhere else in this forum, but it just gave me an error.
Wolfgang Hugemann
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Detection of x-axis and y-axis on a diagram

Post by fmw42 »

whugemann wrote:I think this should work if you search for the crosses in the edges of the frame which exist only four times in the image. If you cut the image to quarters and then search for the cross via Compare, the textual output should provide the right coordinates. With these coordinates you could just draw thicker lines onto the image to get thicker axes.

It would be even easier if the axes would lie at the same location for each diagramm, but I suppose it's not that easy (?).

However, on my Windows computer, I cannot convince Compare to do its job on images which are not off the same size. I tried the code suggested by Fred somewhere else in this forum, but it just gave me an error.
Wolfgang:

Good Idea! Should work.

There was a new parameter added a while ago (after my example) for a compare of non same size images, -subimage-search.

See http://www.imagemagick.org/script/comma ... age-search
see last example at http://www.imagemagick.org/script/compare.php

Fred
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: Detection of x-axis and y-axis on a diagram

Post by whugemann »

This does work, indeed, although it's very slow. I drew a simply 7x7 gif showing a black cross, then performed the following command:

Code: Select all

compare -metric RMSE -subimage-search plug3p.gif cross.gif null:
and if gave the correct coordinates, i.e. 60,9, obviously referring to optimal placement of the upper left corner of the subimage.
Wolfgang Hugemann
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Detection of x-axis and y-axis on a diagram

Post by fmw42 »

whugemann wrote:obviously referring to optimal placement of the upper left corner of the subimage.
Correct. So you have to correct for the offset to the middle of the small image presumably where the cross lines intersect.

And yes, this kind of compare can be rather slow.

P.S. You may also be able to do the compare on the whole image (rather than crop into 4 quadrants and do 4 compares), if you use my script, maxima, to locate the 4 highest scoring locations. Unfortunately, it is a unix bash script and would require Cygwin on Windows.

see script at http://www.fmwconcepts.com/imagemagick/maxima/index.php


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

Re: Detection of x-axis and y-axis on a diagram

Post by anthony »

This is a perfect example of what makes morphology such a useful operator!

Code: Select all

  convert image.png -morphology Close rectangle:50x1  horizontal_lines.gif
This will match any horizontal line longer than 50 pixels, then 'expand the match back'

This image can then be thickened, and overlaid on the original image!

Repeat for vertical lines! Note this will NOT match the dotted vertical line!

Note that 'Open' is the normal operation for object matching like this, However the image is a negative (white background) of what morphology was designed for, so you need to use the complementary operator 'Close'.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply