Ask Your Question
0

Absolute difference between images.

asked 2013-09-25 16:05:50 -0600

mmmax3d gravatar image

updated 2013-09-25 16:07:23 -0600

Hi,

I have two images that seem to be similar at a first sight. I have the following script that calculates the % difference of imgB - imgA. If the error is 0.0 then it calculates the % difference of imgA - imgB.

For this pair of images that seem similar the difference imgB - imgA gives 0.0 but the imgA - imgB gives 26%. How can I see what causes this difference?

How can I calculate the absolute difference of the two images?

here is my code:

import numpy as np
from SimpleCV import Image

sourceimg = Image('44856.png')
target
img = Image('44856_target.png')

diffimg = targetimg - source_img

matrix = diff_img.getNumpy()
flat = matrix.flatten()

numchange = np.countnonzero(flat)
percentchange = 100 * float(numchange) / float(len(flat))
print percent_change

if percentchange == 0:
    diff
img = sourceimg - targetimg
    matrix = diffimg.getNumpy()
    flat = matrix.flatten()
    num
change = np.countnonzero(flat)
    percent
change = 100 * float(num_change) / float(len(flat))

print percentchange
diff
filename = 'diff.png'
diffimg.save(difffilename)

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2013-09-30 23:55:51 -0600

img_diff=(imgA-imgB)+(imgB-imgA)

This works because of the way subtraction of color values occur in simplecv. If the difference is less than zero, it is rounded to 0.

So, if a (x,y) pixel in imgA and imgB be (25,100,75) and (50,70,30), then for that pixel:

imgA-imgB = (0,30,45)
imgB-imgA = (25,0,0)
(imgA-imgB)+(imgB-imgA) = (25,30,45)
edit flag offensive delete link more
0

answered 2013-10-14 07:06:56 -0600

mmmax3d gravatar image

It works indeed! Thanks a lot!

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-09-25 16:05:50 -0600

Seen: 1,426 times

Last updated: Oct 14 '13