Page 1 of 1

Fred's autocaption and rectangles

Posted: 2012-03-06T05:15:48-07:00
by djd
Placing numeric identifiers in a grid (eg a map grid) mostly involves a rectangular area
for the number eg a three digit number. Requiring a square area for the caption could
result in sub-optimal placement in fairly crowded areas. I wonder if anyone has modified
(or can suggest how to) Fred's autocaption script to accept rectangular areas.

Regards

Re: Fred's autocaption and rectangles

Posted: 2012-03-06T11:14:17-07:00
by fmw42
djd wrote:Placing numeric identifiers in a grid (eg a map grid) mostly involves a rectangular area
for the number eg a three digit number. Requiring a square area for the caption could
result in sub-optimal placement in fairly crowded areas. I wonder if anyone has modified
(or can suggest how to) Fred's autocaption script to accept rectangular areas.

Regards
Please clarify. My script does use rectangular areas (as defined by the user), but only finds one best area. It does not do multiple inserts. But as I mentioned in a similar post, if you have a regular grid of things to place, then you know the centers of each area or the upper left corners of each area. You can generate an image of the text for each area using label: properly centered for that size. Then you can flatten all the text images over the grid background (or composite them as generated) using the known locations as offsets in -page or -geometry as desired.

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


If I misunderstand, perhaps you can post a link to your image that you want to label and explain further. An image goes a long way to understanding the problem.

Re: Fred's autocaption and rectangles

Posted: 2012-03-07T21:39:02-07:00
by djd
I refer to the -s option, providing the size of a text square area.

I have not grasped the placement algorithm as yet but I thought it tried to find an area with the largest area of background colour and place the text there - so that it covered least amount of image information.

If the `uncluttered' background was T shaped with the top and the height of the T about the same
as the -s dimension, then the algorithm might position the text square more or less straddling the entire T. However, if the text were rectangular, like a three digit number, it might fit entirely in the top of the T.

There is an example of a numbered grid called IndexedGrid.gif and an example
of an indexed map called Map-4x3-indexed.gif at www.discway.com.au/cmad. There is a `T'
in the indexed grid, but it could have been made a little more `challenging'. Note that each
cell of the grid before indexing was cut out as a separate image and numbered using autocaption.
The individual numbered images were identical with the numbered grid, as one would hope.

For an uncluttered image (at least in the examples under consideration) it would look better
if the text was near the center of the grid. However the captioning algorithm default
position appears to be the top left corner of the image.

If I fully understood Fred's algorithm, I would adjust the text colour transparency number in accordance with a
measure of the image `clutter'.

Regards

Re: Fred's autocaption and rectangles

Posted: 2012-03-07T22:12:17-07:00
by fmw42
I have not grasped the placement algorithm as yet but I thought it tried to find an area with the largest area of background colour and place the text there - so that it covered least amount of image information.
Unfortunately, no it just looks for the first area scanning left to right and top to bottom that is large enough to fit your area. It cannot find the "best" or largest area. It uses IM compare with a rectangle size you specify and the color of the background specified. Compare returns the first match it finds. So if it finds an area larger than your box, it will place the text towards the upper left corner of the area. Unfortunately, it does not know how big the area is, just that it has found an area that is at least large enough to hold your caption box. It has nothing to do with the gravity setting of caption, which in my script is -gravity center, so that the text is center justified within the specified box size.


There is an example of a numbered grid called IndexedGrid.gif and an example
of an indexed map called Map-4x3-indexed.gif at http://www.discway.com.au/cmad. There is a `T'
in the indexed grid, but it could have been made a little more `challenging'. Note that each
cell of the grid before indexing was cut out as a separate image and numbered using autocaption.
The individual numbered images were identical with the numbered grid, as one would hope.

Access Denied to your link. So I am still guessing what the problem is. But you should be able to use -gravity center with caption: to get the T centered in the area. You don't need to use autocaption. You should be able to write a script to loop over each cell, create a caption image with your text on a transparent background and then place the caption image in your grid image. Assuming the grid is regularly spaced, you should be able to compute where to place each box so that it is centered in the grid (along with using -gravity center with caption). That way the text will be centered in each grid cell and center justified.

P.S. What version of IM are you using and on what platform?

Re: Fred's autocaption and rectangles

Posted: 2012-03-08T00:23:40-07:00
by anthony
If you want to find the largest rectangular area (of a specific ratio) in the image then you can use the distance gradient to find it. This is talked about in
viewtopic.php?f=1&t=20269&p=81610#p81610

Re: Fred's autocaption and rectangles

Posted: 2012-03-08T05:51:22-07:00
by djd
There is no ftp access to the link, you have to use your browser which should display the image(s)
and then you can download them from the browser if you wish.

Regards

Re: Fred's autocaption and rectangles

Posted: 2012-03-08T10:43:40-07:00
by fmw42
djd wrote:There is no ftp access to the link, you have to use your browser which should display the image(s)
and then you can download them from the browser if you wish.

Regards

When I click on your link in my browser it comes back with:

Forbidden

You don't have permission to access /cmad/ on this server.

Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny16 with Suhosin-Patch mod_ssl/2.2.9 OpenSSL/0.9.8o mod_perl/2.0.4 Perl/v5.10.0 Server at www.discway.com.au Port 80

Re: Fred's autocaption and rectangles

Posted: 2012-03-08T17:03:08-07:00
by fmw42
anthony wrote:If you want to find the largest rectangular area (of a specific ratio) in the image then you can use the distance gradient to find it. This is talked about in
viewtopic.php?f=1&t=20269&p=81610#p81610
Anthony,

Thanks for the suggestion about morphology distance.

I will keep this in mind and look into it for a newer autocaption when I get some time.

Fred

Re: Fred's autocaption and rectangles

Posted: 2012-03-08T18:43:21-07:00
by anthony
Also the link is readable for me -- at least it is now!
http://www.discway.com.au/cmad/

So the procedure would be make an image of the label, and determine its aspect ratio.
create a mask of the image on defining what are clear and unclear areas.
generate a distance map with that ratio.
Put the image 'center justified' on that the highest (largest clear area) found.

A variation on this is for that clear/unclear mask to ignore 'thin light colored lines'.

I have not tried it by perhaps you can pre-assign such 'light' features with a quite pure black distance (say give it a distance gray value of half the distance across the overlay image). Then if an area of the image has a hard 'not-clear' feature on one side, and a not-so hard 'partal-clear' feature on the other, it will settle on a point closer to that 'partially-clear' moved the label further way from a full 'black' (not-clear) area. Probably best to use this only if the first run failed to find a 'completely clear' area.

Re: Fred's autocaption and rectangles

Posted: 2012-03-08T19:29:58-07:00
by djd
Sorry about the link. It no longer worked for me either.
Have had the ISP fix it and also provide a proper directory listing to the browser.

Regads

Re: Fred's autocaption and rectangles

Posted: 2012-03-08T19:59:09-07:00
by fmw42
One other thought about using autocaption on a grid. Since you know the grid size and spacing, you can create a transparency channel that is fully transparent every where but the cell you want to put a caption in. Then use autocaption and supposedly the compare in the script should only search in that cell. Repeat with a new transparency channel for the next cell, etc.

Anthony,

Is the above reasonable? Does compare ignore any transparent areas? I think you told me that once before.


Another thought? Is it possible to use morphology to take a binary image of the white areas and reshape/erode them into the rectangles with the maximum dimensions to that fits inside the region? Something like a rectangular inside hull? Or perhaps better erode down to the size of the caption area. If so, then one could then extract each rectangle using my separate script and get its size and location and then make a caption image to fit or center inside each area. I don't know if IM can do something like that. But perhaps using the masked morphology using the white areas as a mask? Anthony would have to comment on this. Not really sure if it makes any sense.


Fred