How to deform 2 circles?
2 次查看(过去 30 天)
显示 更早的评论
Hello everybody,
[Problem]: I want to deform a circular images to minimize the difference between them.
Original Images:
Currently done:
close all; clc;clear all;
I1 = imread('Image1.png'); I2 = imread('Image2.png');
I = imshowpair(I1, I2, 'montage');
I = rgb2gray(I.CData);
bw = im2bw(I);
bw = imfill(imcomplement(bw), 'holes');
imshow(bw);
L = logical(bw);
s = regionprops(L,I, 'Centroid','Area','BoundingBox','MeanIntensity');
%%Smallest cmr index
[min_area_cmr,min_cmr_idx] = min([s.Area]);
min_cmr_bb = s(min_cmr_idx).BoundingBox;
cropped_min_cmr_bb = imcrop(I, min_cmr_bb);
[nr nc] = size(cropped_min_cmr_bb);
%%Background
[~,maxGrayLevel] = max(imhist(I));
[row,col]=ind2sub(size(I), min_cmr_idx);
background_im = I.*0+maxGrayLevel;
%%Intensity
averageMeanIntensity = mean([s.MeanIntensity]);
resized_cmrs = background_im;
figure(1)
for k = 1 : size(s, 1)
thisBlobsBoundingBox = s(k).BoundingBox;
subImage = imcrop(I, thisBlobsBoundingBox);
subImage = imresize(subImage, [nr,nc]); %re-sized to smallest
subplot(1, 3, k);
new_I2(:,:,k)= subImage;
imshow(new_I2(:,:,k),[]);
r1 = floor(s(k).Centroid(2)-nr/2);c1 = floor(s(k).Centroid(1) - nc/2);
r2 = nr + r1- 1; c2 = nc + c1 - 1;
binaryImage = im2bw(subImage);
binaryImage = imfill(binaryImage, 'holes');
mask = bwareaopen(binaryImage, floor(min_area_cmr*0.9));
subImage = double(subImage) * averageMeanIntensity/s(k).MeanIntensity;
subImage(~mask) = maxGrayLevel;
resized_cmr(r1:r2,c1:c2) = subImage;
end
[optimizer,metric] = imregconfig('multimodal');
tformmovingRegisteredDefault = imregister(new_I2(:,:,1), new_I2(:,:,2), 'affine', optimizer, metric);
figure(1); subplot(1, 3, 3); imshowpair(tformmovingRegisteredDefault, new_I2(:,:,2))
title('Default registration')
Wanted Output: And I want to deform one of the images in order to minimize the difference between them. Could you suggest me please any working/implemented techniques in Matlab, please?
@Image Analyst
@Walter Roberson
I'll vote for all your answers and would gladly appreciate any comments.
Ivan
0 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!