开发者

Finding differences between two images and update the second image

  1. How do I find the difference between two images?
  2. Replace the difference in the second image to make both images identical?

I've found answers for the first part, but not for the开发者_JS百科 first and second combined. The reason for doing it that way is to save bandwidth.

Sources I've found so far:

  • Comparing two JPEG IMAGES and displaying differences

  • Compare images to find differences

  • https://web.archive.org/web/20141229164101/http://bobpowell.net/lockingbits.aspx

  • http://www.bryancook.net/2009/10/find-differences-between-images-c.html

But, how do I use these to fit my need?


Are you sure that the better solution, to save bandwidth, is not to simply replace image nr. 2?

Supposing that, at least one of images is not on local and that the image size is x bytes. You have two possibilities:

  • To compare the two images, you have to: download it, compare them and the upload the new image. So you'll transfer 2x bytes on network (plus the computation time).
  • To overwrite the 2nd image, you have to: upload the new image. x bytes on network (and no computation time).


If I understood you correctly you have 1 pc with 2 images and another with 1. You want to compare images on pc1 and send the difference to pc2?

Quite an interesting task.

The only optimization algorithm that comes to mind (considering I don't know specialized algrothims for that case) is recursively dividing image into quad-tree, say NE, NW, SW, SE till your reach the certain optimal threshold and then sending to pc2 only the nodes that differ between images.

For example you have image

0000
0010
0011
0000

You divide it into the following quad-tree:

NW: 
00
00

NE:
00
10

SE:
11
00

SW:
00
00

You send following information to pc2: NE 0010 SE 1100

Considering it only takes a byte or int to specify full path (NW->NE->SW) in quadtree you will send

1(NE)+4(0010)+1(SE)+4(1100) = 10

bytes of information instead of original 16.

If you recursively divide your subtree one more time the output bandwidth is going to be 6 bytes instead of 16.


For part 2:

What if you stored the difference as a transparent GIF image? Then to build the final image, you just have to draw the transparent GIF on top of the other image.


As others have said, you should benchmark first to be sure that sending the image diff actually saves bandwidth.

But if you have very large images with relatively few diffs, then this problem looks like a sparse matrix update.

For example if your diff matrix looks like this:

0 0 0 0 0
0 0 0 0 0
0 0 0 1 0
1 0 1 0 0
0 0 0 0 0

Then you could send a sequence of indexes along with the pixel data you want to update (pseudocode):

update = [[2, 3, orig_at(2, 3)], [3, 0, orig_at(3, 0)], [3, 2, orig_at(3, 2)]]

You may be able to further optimize using run-length encoding (in 1 or 2 dimensions) if your diffs typically look more like this:

0 0 0 0 0
0 0 0 0 0
0 1 1 1 1
0 1 1 1 0
0 1 1 1 0

Finally, if your diffs don't have a "typical" shape, then the recursive subdivision idea from this answer is a good general solution.


I have done some analysis on Image Differencing but the code was written for java. Kindly look into the below link that may come to help

How to find rectangle of difference between two images

The code finds differences and keeps the rectangles in a Linkedlist. You can use the linkedlist that contains the Rectangles to patch the differences on to the Base Image.

Cheers !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜