Page 2 of 2
Re: Replace placeholder area with different image
Posted: 2018-12-26T15:22:43-07:00
by fmw42
What do you want to place there? Can you show us the image or the text you want?
If you want to quickly find some colored region that is of a color not in your image (such as a transparent area or red in an image that has no red), the quickest way is to use connected components processing after converting the image to binary. Find the region in the binary image, get its crop coordinates and then crop the original image. See
https://imagemagick.org/script/connected-components.php
If you provide the image or text you want to put there I can show you the commands
Re: Replace placeholder area with different image
Posted: 2018-12-26T15:56:33-07:00
by snibgo
I think the goal is to change the given "from" image to the given "to" image. For example, the rasterized text "Hamburg (HAM)" should be changed to the rasterized text "Bergen (BGO)". Then I guess the goal is to do the same substitutions for many other images.
First step is to make two subimages, one for each of the rasterized texts. These can be made from crops of the samples. Call these, say, "from.png" and "to.png".
Then a script seaches the input image for "from.png". Eg "magick compare -subimage-search -metric RMSE mainimage.png from.png NULL:". If it is found, we get those coordinates. The script then pastes "to.png" in the same location: "magick mainimage.png to.png -geometry +XX+YY main_changed.png".
Those commands can be put in a loop to process any number of files.
Re: Replace placeholder area with different image
Posted: 2018-12-26T19:04:33-07:00
by fmw42
The problem is that compare is too slow. That is why I suggested using CCL to extract the one color regions crop box. Then the other image can be placed at the same offsets. That would be faster. The proviso is that each color must be unique in the image. So if you have multiple images, you would be best to preprocess your image so that all the regions have different colors that you know and the rest of the image was black or transparent.
If compare is too slow and you cannot make unique colors in the image, then try speeding up compare using different resolution sizes and limit the search for the better resolutions. Often just one reduce resolution will speed things up quite a bit. Alternately, if on Unix-like system, try my bash unix Imagemagick script, normcrosscorr, to do FFT based normalized cross correlation. You need to install the FFTW delegate to use that script.
Re: Replace placeholder area with different image
Posted: 2018-12-26T21:24:25-07:00
by snibgo
Yes, compare may be too slow. I have BAT scripts and process modules that are much faster ("multi-scale").
But I'm not sure I understand the problem yet.