I would like to know if it's possible to split a picture according to another picture of same size. Let's call these pictures, the actual picture and the mask picture. The mask picture has solid colored areas on a transparent background. Let's call these areas submasks and their colors as submask colors. The colored areas represent areas in the actual picture that contain only interesting things in that color. So what I would like to do is split the actual picture into subpictures by using the submasks as selection tools.
In addition I want to transform these subpictures into bitonal ones. That should be done by converting everything else than the corresponding submask color in the subpicture to white and the subpicture color itself to black. It's probably reasonable constraint if we assume the submasks to represent only rectangular shapes.
Here's a few pictures to illustrate what I mean [EDIT: Link now works]:
http://www.cs.helsinki.fi/u/tglehto/tmp/IM/
I did already find something from the forums concerning this thing, especially close seems to be these:
viewtopic.php?f=1&t=10377&p=32751&hilit ... age#p32751
http://www.imagemagick.org/Usage/scripts/segment_image
I'm starting to get a hang of this script, but I wonder is this really the only way of doing this? It takes forever to go through all the pixels in the picture. What if I'd do something like:
Loop untill image is empty:
1. check: only corners of the image and collect pixel and color data if they are not transparent
2. trim
3. if image not changed 4 and 5 else go repeat 1
4. check: only edeges of the image and collect pixel and color data if they are not transparent, make such edgeconnected areas transparent
5. try to trim again
(maybe we need to also store information as to what corner pixels we got from each continuous area: NW, NE, SE, SW)
Btw is it even possible to get the pixel location data in relation to the original picture?
Myabe through the percieved virtual canvases? How to use them? What does this mean?
Ok. Now if we know the colors and their locaisons (at least 1 pixel per color), then we can go through each of those coordinates and color in the original picuter, removing everything else (read=making it white) from the picture excpet the continuous area of that color connected to that pixel. Also change the color of that area to black. Store all these intermadiate pictures for later use as masks (also don't forget the colordata related to that mask). For each pixel to process of coures always use the original picture.The page or virtual canvas information of the image is preserved allowing you to extract the result of the -trim operation from the image. Use a +repage to remove the virtual canvas page information if it is unwanted.
One at a time apply the masks on the actual picture and make the color transformation as I previously dicribed. Maybe also tirm the results as well.
Does that sound insane or brilliang ?
In the script I mentioned there we're some parts that someone could enlighten a bit:
I don't quite understand the -write miff:- thingy, could someone explain it a bit? In my pathetic attemps to understan them I tried to run this:
convert example_img_mask.tif -write miff:- -fuzz 0% -fill none -draw matte 5x5+20+20 floodfill example_img_test.tif
and made the windows cmd print cool smileyfaces, arrows, symbols and such and the all so beloved pc beeper to play mozart..
If I remove the -write miff:- part and quote draw-triggers values. It removed the background color from the image. How did the coordinates have anything to do with this? It seems to do the same thing no matter what they are?
This line is a total mystery for me.
convert miff:- -reverse -layers OptimizeTransparency -reverse "$2"