Pixel Shift Calculation between two very similar images

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
Post Reply
NukerDoggie
Posts: 12
Joined: 2015-04-04T19:06:28-07:00
Authentication code: 6789

Pixel Shift Calculation between two very similar images

Post by NukerDoggie » 2017-07-14T10:46:01-07:00

I have two screen shot images (PNGs) and I want to calculate the max pixel geometric shift between the objects in the images. Both images are identical size and color depth. Some "objects" in the 2nd screen shot are shifted geometrically as compared to the 1st screen shot.

I have used IM to convert both images to grayscale, then did -canny 0x0+1%+3% to perform edge detection, then I changed all white pixels in the 1st screen shot to green1, and then I blended the two images with 50% blending. I get a result image that nicely shows the geometric shift everywhere it occurs, with green lines shadowed by gray lines in these regions.

Now, how can I use IM to scan this result image and tell me the max geometric shift, in pixels, for the image?

Or, is there a better and more efficient way to perform the entire operation and to find the max geometric shift between the two images?

User avatar
fmw42
Posts: 22081
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Pixel Shift Calculation between two very similar images

Post by fmw42 » 2017-07-14T14:50:34-07:00

Please always provide your IM version and platform, since syntax and scripting may differ. Can you post your two edge images to some free hosting service and provide the URLs here?

NukerDoggie
Posts: 12
Joined: 2015-04-04T19:06:28-07:00
Authentication code: 6789

Re: Pixel Shift Calculation between two very similar images

Post by NukerDoggie » 2017-07-14T15:35:59-07:00

Hi Fred,

I am using ImageMagick-6.9.3-Q8 on Windows 7.

Here is the blended image:

https://sabercathost.com/4X6e/frame0_blend.png

Here is the baseline image:

https://sabercathost.com/4X6f/frame0_green_1st.png

Here is the 2nd image:

https://sabercathost.com/4X6g/frame0_canny_2nd.png

In the blended image, note the rotated "Hello World" text - it shows some differences in rendering that I expect and wish to quantify.

NukerDoggie
Posts: 12
Joined: 2015-04-04T19:06:28-07:00
Authentication code: 6789

Re: Pixel Shift Calculation between two very similar images

Post by NukerDoggie » 2017-07-15T11:49:18-07:00

Sorry for the 60-sec delay when you want to download each image above from SaberCatHost - lots of people elsewhere said this was the best free file hosting site...oh well....should have checked it out first.

I hope this doesn't prevent people from taking a look at the images.

User avatar
fmw42
Posts: 22081
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Pixel Shift Calculation between two very similar images

Post by fmw42 » 2017-07-15T12:01:42-07:00

I have downloaded them -- yes, it was a pain -- but so far no good ideas how to do what you want.

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

Re: Pixel Shift Calculation between two very similar images

Post by snibgo » 2017-07-15T13:00:11-07:00

After 60 seconds, nothing happened for me. No download, no nothing.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 22081
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Pixel Shift Calculation between two very similar images

Post by fmw42 » 2017-07-15T14:28:08-07:00

snibgo wrote:
2017-07-15T13:00:11-07:00
After 60 seconds, nothing happened for me. No download, no nothing.
You have to wait, then a button appears and you have to click the button. A really annoying web site for downloading, since you have to wait for each image separately even if you ask to download each page. It will wait for one page to finish before timing the next one.

The OP might consider using dropbox.com (and make the images shareable).

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

Re: Pixel Shift Calculation between two very similar images

Post by snibgo » 2017-07-15T15:03:29-07:00

I think I had a button, which I pressed, with no luck. It was yesterday, and I forget.

I have enough internet problems (terrible speeds, when it works at all) that I really can't be bothered with web sites that are deliberately slow.
snibgo's IM pages: im.snibgo.com

NukerDoggie
Posts: 12
Joined: 2015-04-04T19:06:28-07:00
Authentication code: 6789

Re: Pixel Shift Calculation between two very similar images

Post by NukerDoggie » 2017-07-16T07:41:32-07:00

For calculating the geometric pixel shift, I can do a horizontal scan, and a vertical scan of the image, and count the distances between green and gray pixels. I can average the numbers, or get max variation. That might suit my purposes well enough. I'll need to use a C++ pgm to do that - not a problem.

It gets a little tricky when the object that's being scanned is at a steep angle, like the rotated text. Depending on the angle and whether I'm scanning horizontally or vertically, the pixel count between green and gray pixels might be exaggerated. So I'll have to make the scan smart, by not letting it confuse a green-gray pixel void caused by a vertical shift with one caused by a horizontal shift, and vice-versa. This is mostly an issue when the scan intersects the rotated object at a very oblique angle.

IM has gotten me all the way to the doorstep of what I need.

NukerDoggie
Posts: 12
Joined: 2015-04-04T19:06:28-07:00
Authentication code: 6789

Re: Pixel Shift Calculation between two very similar images

Post by NukerDoggie » 2017-07-16T10:41:30-07:00

One prospect for performing the geometric shift analysis I'm interested in:

https://phys.org/news/2017-01-medical-s ... astly.html

NukerDoggie
Posts: 12
Joined: 2015-04-04T19:06:28-07:00
Authentication code: 6789

Re: Pixel Shift Calculation between two very similar images

Post by NukerDoggie » 2017-07-20T12:14:43-07:00

I did solve this by using a custom C++ pgm and performing a pixel-by-pixel scan of the blended image after sub-dividing it into areas of interest based upon a difference image. I scanned each area of interest bi-directionally, both horizontally and vertically, and accumulated metrics around distances between the different colored pixels, and implemented some weighted average math to snuff the handful of wild errors. What I got was a collection of very reasonable and very accurate metrics which are localized to each area of interest. I have thus achieved my goal of determining the geometric pixel shift in the regions of difference between two similar images. I can't share the code because it belongs to the Company I work for. But what's interesting about this solution is that it works with many different sets of similar images, very accurately identifies discrete objects and creates areas of interest around them, accurately quantifies the geometric shifts, and uses no neural network implementation.

IM brings you to the doorstep, and you then just have to do some smart scanning and metrics calculations. Thanks IM!!!

Post Reply