how to calculate the distance between matching points of two different images

4 vues (au cours des 30 derniers jours)
Hello,
I'm having trouble to find an easy and automatic way to calculate the distance between possibly matching points in two different images.
I had an original BW image and its corresponding binary matrix. I applied an affine transformation (a shear) to the image, to get two new images: one shifted to the left and the other one to the right. Now the image matrices are no longer binary as I have values ranging from 0 to 1 due to the transformation. I'd like to calculate the distance between the possible matching points in the two images, that is the points that have approximately the same location in both images, and not only the two points that corresponded to one point in the original image (before the transformation). To do so, I thought I first had to get the centre of each "dot" in both images and then do something to calculate the distance between several points. I tried the centroid method of the regionprops function and the imfindcircles but as the dots are not really circular and can overlap, both methods are far from giving me the centres of the dots. So i'm currently stuck here, and don't manage to think of another way to do it! It'd be very nice if someone had any idea about how to handle this problem!!
Some of the code I use to create the new images (left/right):
for frame_ndx = 1 : length(frame_cond) frame_ndx se = strel('disk',4);
x = linspace(-1,1,sz);
[X,Y] = meshgrid(x,x);
[T,R] = cart2pol(X,Y);
threeshold = 1 - (Dot_nb / sz^2);
Rd = double(rand(sz,sz)>threeshold);
Rd(R>0.95 | R<0.06)=0;
Rd = imdilate(Rd,se);
if (frame_cond(frame_ndx) == 1) % creates a decorrelated pattern for the right image
Rd_decor = double(rand(sz,sz)>threeshold);
Rd_decor(R>0.95 | R<0.06)=0;
Rd_decor = imdilate(Rd_decor,se);
end
slant_coeff = 0.0361; % this value gives a Shear angle of 4.13°
if (frame_cond(frame_ndx) == 2)
tform_l = maketform('affine',[1 0 0; slant_coeff 1 0; 0 0 1]);
tform_r = maketform('affine',[1 0 0; -slant_coeff 1 0; 0 0 1]);
else
tform_l = maketform('affine',[1 0 0; -slant_coeff 1 0; 0 0 1]);
tform_r = maketform('affine',[1 0 0; slant_coeff 1 0; 0 0 1]);
end
Rd_l = imtransform(Rd,tform_l,'size',size(Rd),'FillValues',0);
Rd_r = imtransform(Rd,tform_r,'size',size(Rd),'FillValues',0);
if (frame_cond(frame_ndx) == 1) % creates a decorrelated pattern for the right image
Rd_r = imtransform(Rd_decor,tform_r,'size',size(Rd_decor),'FillValues',0);
end

Réponse acceptée

Image Analyst
Image Analyst le 7 Nov 2015
Presumably the affine shear just made it so the two images are aligned and they are still both of the same size and have the same coordinate system. So you did not enlarge the canvas of one when you sheared it. So just get the coordinates of the two points and use the Pythagorean theorem. What's the difficulty? Perhaps we'd know if you attached your images. I'm guessing that you'd just find the point in each image and compute the Euclidean distance. Is that wrong?
  2 commentaires
izziehb
izziehb le 7 Nov 2015
Actually, what I want to do is ,first getting the centre of every single dot, which in the image matrix should correspond to a specific pattern: pattern=[0,0,1,0,0;0,0,1,0,0;1,1,1,1,1;0,0,1,0,0;0,0,1,0,0]; except if dots overlap. Then I'd like to get the distance between one point in the first sheared image and several points in the second sheared image, depending on one location criterion, such as an area of 10*10 pixels. I figured out, getting the centre of every single dot was the first step to make things easier, but I don't know how to look for a specific pattern in my matrix, as they don't have the same size. Here is one of my sheared image, don't know if it can help!
Image Analyst
Image Analyst le 7 Nov 2015
Usually windows are an odd size. So to extract a window +/- 5 pixels around your circle's (xCenter, yCenter) point you'd do this
subImage = grayImage(yCenter-5:yCenter+5, xCenter-5:xCenter+5);
Now you can examine those 121 pixels in an 11-by-11 array in whatever way you want. For example if you want to find the area fraction you'd do
areaFraction = sum(subImage(:))/(11*11);
Or to see what pixels are different from your pattern:
diffPixels = sumImage ~= pattern;
or whatever else you want to do.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by