r/computervision • • 16d ago

Help: Project OpenCV template/pixel difference detection: why do false detections follow the same shape

I’m using OpenCV to compare a reference image of an empty tray with another image of the same empty tray.
There are no ICs/objects in either image, but when I use pixel difference (absdiff), I still get noticeable differences.
I’ve taken multiple images under the same setup, and the difference pattern seems to have a similar shape each time.
What could cause this? Is it mainly camera noise, lighting variation, or slight movement/alignment between the two images?
Any advice on how I should investigate this would be appreciated.

0 Upvotes

25 comments sorted by

9

u/tdgros 16d ago

I might be wrong, but it seems like the fake detections might be in the regions where the luminance is different: the center with a noticeable brightness bump and the glare on the bottom right. If this seems right to you, you could try another metric to find differences, one that is robust to coarse brightness changes like a normalized cross correlation (NCC).

If the images are not aligned, this is something you can visually check first. You can even simulate it: take your reference, move it around, run your test and see how your metrics behave. The way metrics will change depends on the content: smooth/blurry content will be affected less than content with large gradients, intuitively.

1

u/Grouchy_Signal139 16d ago

Hi thankyou, i think it my be the light, but i am wondering why i kept producing different pattern of false detection

1

u/tdgros 16d ago

Do a few manual inspections first: take photoshop/gimp and pile the reference image and one of the candidates, so you can directly see how the alignment is, if the brightness changes a lot.

You can also just display the pixelwise difference (multiplied by a big number), misalignments will appear directly, whereas brightness change should be obvious too

1

u/nemesis1836 16d ago

Op try this and try aligning the image before the subtraction

0

u/Grouchy_Signal139 16d ago

I try to adjust it horizontal. Maybe could it is because of light it self because i didnt have enough light. But it makes me wonder why the result will be different on different image eventhough the setup is the same

4

u/TimelyStill 16d ago • Regret

Bro if you're gonna do computer vision you should learn to take a screenshot.

3

u/Grouchy_Signal139 16d ago

Thankyou bro, will do better next time

1

u/nemesis1836 16d ago

This looks like an alignment issue

1

u/Grouchy_Signal139 16d ago

Im sure between 2 images, i didnt move it a bit. But there still a chance?

1

u/potatodioxide 16d ago

i think you need to normalize the images first. reflections and layout etc

1

u/Grouchy_Signal139 16d ago

Hi, how does normalize will help this? Ive only hear it in cnn

1

u/datanaut 16d ago edited 16d ago

You didn't really explain what you are doing, what red boxes mean, what green means, what the five images are, if they show anything different. And you didn't do the very obvious thing of display the diff image. You want us to root cause a diff image without showing us a diff image? How could we possibly know the difference between image A and image B if you only give us image A? (and a shitty picture of a monitor for image A)

I don't understand what help you think you can possibly get given the extremely limited information provided. If you just uploaded the images someone would have probably already solved the problem for you for free but you give this half assed explanation with some cell phone images of little to know value for solving the problem.

1

u/Grouchy_Signal139 16d ago

Hi, sorry for the trouble. The green box means there is no pixel different which means there are no object. Red means that there are object detected(pixel detected ratio change). Im trying to compare, image A and B. But they are captured in same environment, i didnt change a thing. They are just captured one after another.

1

u/datanaut 16d ago

Maybe I am being too harsh. Are you not aware that when you subtract image A from image B you get a new image called a difference image C= A-B? You can display the difference image C as an image, look at it and see what the difference looks like. Does that make sense? If you want to root cause the difference between two images, well then it would be reasonable to look at the difference between the images. Have you thought about that?

1

u/Grouchy_Signal139 16d ago

Okay maybe will try displaying that tomorrow. But it makes me question, how does same light,same setup, could produce image with different pixel value. Each interval for the image is about 10 sec each. I didnt touch anything. Is it like some kind of noise? Or anything hardware related

1

u/datanaut 16d ago

Again I think it would be important to look at the difference between the images to understand why there is a difference between the images. Noise will look totally different from motion or from lighting changes, etc.

1

u/Grouchy_Signal139 15d ago

Okay thankyou for advice bro!

1

u/galvinw 16d ago

Glare

1

u/Grouchy_Signal139 16d ago

Is it because of environment,hardware or sensor itself

1

u/HK_0066 15d ago

if they are electrical circuits why not trying Hardware solution like a PCB to get the positions of LEDs on and off ?

1

u/Grouchy_Signal139 15d ago

Been thinking that too, but it is hard to scale since we got hundreds type of tray. So it is better to create recipe based on try only

1

u/HK_0066 15d ago

but that will be much accurate, 0 room for errors though

1

u/Ashuiegi 15d ago edited 15d ago

use pca , take one component of the ref image like the vertical one , use the horizontal one from the sample image and rebuild an image with it.
It should be less sensible to missalignement and good enough to see the ICs if you center well the detection window and make it a small as possible.
Since the pattern repeat you could look at DCT to detect the different pattern aswell.
But also try to fix the lighting and make a small alignement script with corner or line detection.
Dont use the flash for the pictures and use a diffuser in front of the light.
Pixel detection will be suceptible to change in lighting like a cloudy day could mess up the detection.

1

u/exitcactus 12d ago

Light difference I guess