OK. One way to do that is to use compare to search the larger image with logo to find the best matching location. This is a slow process so one should resize both the image and logo to get a close matching location. Then crop the large image with a bit of padding and search it for the exact match.
Unfortunately, I do not use Windows and the syntax for doing computations is not something I know how to program. But I can give you an outline.
The information returned from a compare is the metric score of how well it matched in the range 0 to quantum range, the score in the range 0 to 1 in parenthesis and the x,y pixel location of the top left corner of where the logo is matched in the large image.
See
https://imagemagick.org/script/compare.php
https://imagemagick.org/Usage/compare/
Input:
Logo:
Code: Select all
magick compare -metric rmse -subimage-search ( witch.png purplelogo.png -resize 25% ) null:
2739.99 (0.0418096) @ 188,1
Compute the location in the full resolution image
x=188*4=752 subtract 10 = 742
y=1*4=4 subtract 4 = 0
purplelogo.png has dimensions 142 × 137 so we pad by 20 in each direction
So now process the original image but crop crop it at 162x157+0+742 so we only search a small region
Code: Select all
magick compare -metric rmse -subimage-search ( witch.png -crop 162x157+742+0 +repage ) purplelogo.png null:
0 (0) @ 11,2
So the location in the uncrossed image is x=11+742=753 and y=2+0=2
So now just change the logo to be pure white and place it over the location
Code: Select all
magick witch.png -alpha off ( purplelogo.png -alpha opaque -fill white -colorize 100 ) -geometry +753+2 -compose over -composite witch_white.png
Another method would be to convert the image to binary and use connected-components to get the bounding box where the smallest region is located, assuming it is the logo. Then use the bounding box to create a white region and place it over the original image. See
https://imagemagick.org/script/connected-components.php
Code: Select all
magick witch_binary.png -type bilevel ^
-define connected-components:verbose=true ^
-define connected-components:mean-color=true ^
-define connected-components:area-threshold=5000 ^
-connected-components 4 null:
Objects (id: bounding-box centroid area mean-color):
6: 754x855+386+0 867.1,435.7 446758 gray(255)
0: 463x855+0+0 196.9,416.5 331007 gray(255)
3: 423x855+249+0 496.1,453.8 181988 gray(0)
8: 143x147+749+0 821.0,71.7 14947 gray(0)
Get the bounding box of the smallest remaining black region
143x147+749+0
Code: Select all
magick witch.png -alpha off ( -size 143x147 xc:white ) -geometry +749+0 -compose over -composite witch_white2.png
I leave it to you to script either approach in Windows.