Need help REMOVING pixels that don't exist in BOTH images

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.
Locked
austech360
Posts: 6
Joined: 2019-06-15T02:00:56-07:00
Authentication code: 1152

Need help REMOVING pixels that don't exist in BOTH images

Post by austech360 »

I have 2 images, Sometimes three. For simplicity, we shall name them Math1, Math2, and Math3.

I have found a way to do the exact thing I want to do. However, it leaves pixels half alpha, and it doesn't give as consistent of a result as I'd like. I'd like it to leave no alpha pixels behind, on a black background.

Math 1 has the words
Math 2 has the same words, But the stuff surrounding the words, is different, The images are the same size, and look almost identical if you don't zoom in to look at each pixel. But I need this down to PIXEL BY PIXEL precision.

The word MATH is in red, and convert changes to red, so that's part of my problem maybe?

I need a way to compare the two images, leaving ONLY the identical pixels in PERFECT condition, Meaning that they are ONLY left if they match position and color EXACTLY between the two. The Identical pixels should be saved in result.bmp

I don't care if this takes 5 lines or even 10. as long as I can reliably get JUST the DELTA, and nothing else.


Any help would be greatly appreciated!


These are BMP images.

Math1
https://imgur.com/HRdOhtz
Math2
https://imgur.com/Ux2NJ5C
result.bmp
https://imgur.com/OZMtqV0
If you open this in an image editor, you can see that the red pixels are alpha, and there are still pixels that don't appear in the first image, visible. Thoughts?

Also, Anything that isn't identical pixels, it would be great if I could have them go to black.
The method outlined https://graphicdesign.stackexchange.com ... he-differe <<HERE is how I got result.bmp

Again, Thank you so much!

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Need help REMOVING pixels that don't exist in BOTH images

Post by snibgo »

I'm not sure what result you want. Where the pixels are identical, you want those pixels. Where they are not identical, you want transparent pixels. Is that correct?

Code: Select all

magick HRdOhtz.png ( +clone Ux2NJ5C.png -compose Difference -composite -fill White +opaque Black -negate ) -alpha off -compose CopyOpacity -composite afk_script_out.png
Image

Or if you want different pixels to become black, then flatten the result against black:

Code: Select all

magick HRdOhtz.png ( +clone Ux2NJ5C.png -compose Difference -composite -fill White +opaque Black -negate ) -alpha off -compose CopyOpacity -composite -background Black -compose Over -layers Flatten afk_script_blk.png
Image
snibgo's IM pages: im.snibgo.com

austech360
Posts: 6
Joined: 2019-06-15T02:00:56-07:00
Authentication code: 1152

Re: Need help REMOVING pixels that don't exist in BOTH images

Post by austech360 »

That's VERY close to right! I wasn't clear. I've had a REALLY tough day today. Been trying to repair garden hoses to get water to crops, and every hose I repair, somehow, magically, causes another hose somewhere down the line to fail, I'm about 200 ft from water, so you can imagine the day I'm having!

I didn't want the different pixels at all. I wanted all pixels that didn't exist in both images to become black. So those should be on an all black background.

The idea I'm having. Is I can snap an image with command line of an area of the screen, then do it again when the conditions are different, then get the result, then compare that result with ANOTHER capture, so each time this is done it in theory, reduces pixels that aren't black, increasing the ones that are black, until eventually, it stops changing, meaning it's trained for all conditions of anti aliasing that could be surrounding it.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Need help REMOVING pixels that don't exist in BOTH images

Post by snibgo »

austech360 wrote:I wanted all pixels that didn't exist in both images to become black.
I don't understand. Pixels exist. All pixels, in both images, exist.
A pixel in one image may be the same as the corresponding pixel in the other image. Or it may be different.
snibgo's IM pages: im.snibgo.com

austech360
Posts: 6
Joined: 2019-06-15T02:00:56-07:00
Authentication code: 1152

Re: Need help REMOVING pixels that don't exist in BOTH images

Post by austech360 »

Oh! Oh my lord. Okay! I get it now! Let me change a few things with the source images to be closer to real world cases and I'll see if it works the way I hope it does! Thank you! I think you've helped me before with something similar with color curves!

Locked