modifying IM to include a characterization routine

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
toasty
Posts: 16
Joined: 2012-12-06T17:56:02-07:00
Authentication code: 6789

modifying IM to include a characterization routine

Post by toasty »

I am using imagemagick to do some basic image processing. Basically identifying these circular features as shown here:
original image:
Image
characterized:
Image

In the above image, each circle has a position (denoted by the blue x) and radius (denoted by the blue circle) that is identified by the routine. The red x's are the "ideal" location of the centers, basically with the jitter removed. We are interested in knowing the variation (sigmas) of each feature, so I needed to do a bit of processing to identify the actual centers and the ideal centers.

I use the FFT and correlation with a known circular kernel to identify the size and position of each feature. Right now I have to do it rather inefficiently. I write my own program to call imagemagick with the appropriate parameters. IM does the FFT, processing in the frequency domain and IFT back into the time domain. I then save it as a pgm which I can read by my program to do the final post-processing to extract the information such as the island centers etc. The program is currently written in C.

The program also produces a txt file which looks like this:

Code: Select all

#       x     y    x_ideal y_ideal  dist    r     metric  value
  0    252   17     254      11     6.32    15   3278   7609
  1    321   17     318      12     5.83    14   3660   7459
  2    384   17     382      12     5.39    15   2822   7457
  3    761   16     762      19     3.16    14   2823   7679
  4    821   16     825      20     5.66    14   3976   8245
  5    445   15     446      13     2.24    14   2849   7857
  6    574   15     574      16     1.00    14   2610   7702
  7    697   17     700      18     3.16    15   2189   7733
  8   1013   20    1012      21     1.41    16   3396   7541
which gives details for each circle in the picture identified

I am interested in learning how to modify IM to somehow merge my routine to be called from within IM. Right now my program is called as follows:
characterize -N 1200 -M 830 -r 10 -R 22 -B 2 016216.jpg
This assumes an image of size 1200x830, and does a radius search from 10 pixels to 22 pixels and includes a blur of radius 2 in the kernel. It then convolves 016216.jpg with circular kernels within the given radii in the given range and finds the peaks which denote the locations of maximum correlation. I also have an algorithm to determine the best fit radius.

I would like to work on integrating these features back into IM, I envisage it being called, perhaps something like this:
convert 016216.jpg -geometry 1200x830+10+22 -blur 2 -characterizeCircles

Could someone give me a leg-up into how to edit the code for IM to integrate my external program in? If there is interest, to have such capability in IM, I would be happy to contribute the code back.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: modifying IM to include a characterization routine

Post by anthony »

This is very advanced, and while FFT handling is available in IM, it is in its infancy.

You say you already do some of this. Can you provide some code demonstrating the process you have? We many be able to help inprove it, as well as allow others to make use of the work you have already done to do other things.

On thing I noticed in your example is that there appears a global offset or mis-match between the blue and red 'x's that is in all but two cases the blue 'x' is to the left of the red 'x' that seems to me to mean the image or the red 'x' grid is mis-aligned (a global offset). Only once you get that would you check the distribution of the jitter seen.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply