Page 1 of 1

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

Posted: 2012-01-15T10:56:08-07:00
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

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

Posted: 2012-01-15T12:08:01-07:00
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.

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

Posted: 2012-01-15T12:27:54-07:00
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.

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

Posted: 2012-01-15T13:30:27-07:00
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/

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

Posted: 2012-01-16T06:34:13-07:00
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.

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

Posted: 2012-01-16T11:47:04-07:00
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

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

Posted: 2012-01-16T13:44:42-07:00
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.

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

Posted: 2012-01-16T13:49:43-07:00
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

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

Posted: 2012-01-23T00:00:52-07:00
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'.