Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to register (align) two circular grayscale images using a boolean mask to prevent them simply being aligned on the fixed circular border. There are also small fixed circular regions in the image that cause further problems (image artifacts, black dot marks).

In the Mathematica documentation (https://reference.wolfram.com/mathematica/ref/ImageCorrelate.html) there is a simple example for image correlation with a circular mask.

Here is an example image:

example

Here is the code I put together using ImageCorrelate, I want to use this, except for larger images then are in the example:

(*note this mask isn't complete*)
mask = ColorConvert[
   Image@Rasterize[
     Graphics[{{White, Disk[{0, 0}, 700]}, {Black, 
        Disk[{70, -20}, 60]}}, 
      PlotRange -> {{-800, 800}, {-800, 800}}, Background -> Black], 
     ImageSize -> 500, RasterSize -> 500], "GrayScale"];

pos = Position[Flatten[ImageData@mask], 1.];
f = NormalizedSquaredEuclideanDistance[Extract[#1, pos], Extract[#2, pos]]&;

image1 = Import["https://dl.dropboxusercontent.com/u/3730003/map4__00001.jpg"];
image2 = Import["https://dl.dropboxusercontent.com/u/3730003/map5__00011.jpg"];

(*this takes forever...*)
corr = ImageCorrelate[image1, image2, f];
minOffset = PixelValuePositions[corr, Min[ImageData[corr]]][[1]] - ImageDimensions[image1]/2;

How can I make this more efficient such that it can be used on larger images?

I've tried to make my own compiled version of NormalizedSquaredEuclideanDistance, however I haven't been able to figure out how to deal with arbitrary length vectors...

Some code borrowed from: Image correlation

To follow up on @bills comment, I did try ImageCorrespondingPoints and ImageAlign, however, they often find matching points on the static boundary as corresponding points which would prevent accurate alignment. I couldn't figure out how to implement some sort of boolean mask. Cropping a square (code below) from the center of the image helped the situation but the black spots still cause problems.

cropper[image_] := ImageAdjust[ImageCrop[image, 1000]];

alignerKey[image1_, image2_] := Module[{cropped1, cropped2, transform},
  transform = FindGeometricTransform[cropper@image1, cropper@image2, "Transformation" -> "Translation"];
  ImagePerspectiveTransformation[image2, Last@transform, DataRange -> Full]
  ]
share|improve this question

put on hold as off-topic by Dr. belisarius, m_goldberg, bbgodfrey, MarcoB, Louis 17 hours ago

  • The question does not concern the technical computing software Mathematica by Wolfram Research. Please see the help center to find out about the topics that can be asked here.
If this question can be reworded to fit the rules in the help center, please edit the question.

    
What exactly do you want to identify here? Are you trying to match the circles in the two images to each other? (It might be clear to other people but I'm confused) – Vincent Tjeng Mar 2 '14 at 22:52
    
@VincentTjeng I'm trying to align (register) the two images. – s0rce Mar 2 '14 at 23:56
1  
Did you try ImageCorrespondingPoints or ImageAlign? They are likely to be much faster. – bill s Mar 3 '14 at 0:04
    
@bills, yes I did try ImageCorrespondingPoints and ImageAlign, however, it they often find matching points on the static boundary as corresponding points which would prevent accurate alignment. I couldn't figure out how to implement some sort of boolean mask. Cropping a square from the center of the image helped the situation but the black spots still cause problems. – s0rce Mar 3 '14 at 2:13
4  
I'm voting to close this question as off-topic because the OP used an image server that doesn't allow access to the files. So it is not possible to test the code and/or design a new one – Dr. belisarius yesterday