Message Boards Message Boards

0
|
911 Views
|
4 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Spot the difference

Posted 4 months ago

Image

I would like to make the program to find the differences (total 10 differences) of the attached image by making circle at the differences in the original image.
but the offset image (alignedRightImage) has a error. why isn't the offset image treated as image file?

And does anyone have an experience like this program?
Could you tell me a comment to make this script?

I attached notebook file.
Thank you
Okayasu

POSTED BY: Shinsuke Okayasu
4 Replies
Posted 4 months ago

I'm sure some of this can be streamlined, but I haven't used these image processing functions much so I'm just doing what seems to make sense. I'm taking image as the image you provided.

(* Let's get rid of the border *)    
croppedImage = ImageCrop[image]

(* Let's slice off the left image. It will be our reference image. *)
leftImage = ImageTake[croppedImage, All, {1, Floor[ImageDimensions[croppedImage][[1]]/2] - 1}]

(* Let's slice off the right image. I'm taking a slightly smaller image to avoid edge artifacts. Maybe this isn't necessary.  *)
rightImage = ImageTake[croppedImage, {2, -2}, {2 - Floor[ImageDimensions[croppedImage][[1]]/2], -2}]

(* Now we can use ImageAliign. Unfortunately, an edge artifact crops up, so we'll need to "erase" that later. *)
{alignedLeft, alignedRight} = ImageCrop[#, targetDims] & /@ ImageAlign[{leftImage, rightImage}, Background -> Black, TransformationClass -> "Translation"]

enter image description here

(* The edge artifact can be seen as a border. *)
borders = BorderDimensions[alignedRight]
(* {{1, 0}, {0, 0}} *)

(* Here we clean that up. I'm taking a bit extra, because I think there was also some anti-aliasing. *)
{cleanLeft, cleanRight} = ImagePad[#, -1 - borders] & /@ {alignedLeft, alignedRight}

(* We can see the diffs now. *)   
diff = ImageDifference[cleanLeft, cleanRight]

enter image description here

Unfortunately, the diff doesn't create nice solid components. The little details break things up into many small components. What I decided to do was to blur this diff, hoping that this will connect nearby details. I had to fiddle around to find a blurring radius that worked nicely. I also binarized it for accuracy. Here is what it looks like:

Blur[Binarize[diff, .4], 6]

enter image description here

My plan now is to use MorphologicalComponents. Here's what we can get now:

MorphologicalComponents[Blur[Binarize[diff, .4], 6], Method -> "BoundingDisk"] // Colorize

enter image description here

I'll combine the next few steps. We create perimeters, thicken them so they can be seen more easily, color them red for the same reason, and overlay this with our reference image.

diffOverlay = 
 ImageRecolor[
  Colorize[
   MorphologicalTransform[
    MorphologicalPerimeter[MorphologicalComponents[Blur[Binarize[diff, .4], 6], Method -> "BoundingDisk"]], 
    Max]], 
  {Black -> Transparent, _ -> Red}]

enter image description here

ImageCompose[cleanLeft, diffOverlay]

enter image description here

POSTED BY: Eric Rimbey

Thank you for helping!

I reproduce your code in my nb file.
I did not know how to fix figures by ImagePad and ImageCrop.

I have a question about below code in taking the image.
Why is the image needed floor?
Does the image have a issue?

(*Let's slice off the left image.It will be our reference \
image.*)leftImage = 
 ImageTake[croppedImage, 
  All, {1, Floor[ImageDimensions[croppedImage][[1]]/2] - 1}]
POSTED BY: Shinsuke Okayasu

Thank you for your reply.

My question is completely solved!

Okayasu

POSTED BY: Shinsuke Okayasu

This is a very intriguing work, Eric.

POSTED BY: M.A. Ghorbani
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract