Why imregtform registration fails on similar images
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Dear all, I am currently working on a project requiring image registration. I have to very similar images
However, a slight mismatch exists between them requiring an affine trasformation to get them perfectly matched. Unfortunately, it does not work and I cannot find a way to make it work. This is the result I get executing the code below. Both images in tif format and the code are in the zip file ready to run since I cannot upload tif here.
ref = imread('Reference.tif');
im = imread('Image.tif');
[optimizer, metric] = imregconfig('monomodal');
optimizer.GradientMagnitudeTolerance = 1e-8;
optimizer.MaximumIterations = 3000;
optimizer.MinimumStepLength = 1e-7;
transform = imregtform(im, ref, 'affine', optimizer, metric,'DisplayOptimization',0);
reg = imwarp(im,transform,'cubic','OutputView',imref2d(size(im)),'FillValues',0);
subplot(1,3,1)
imshow(ref,[]);
subplot(1,3,2)
imshow(reg,[]);
Can your provide any suggestion? What can I do to improve outcome of registration? I have several images similar to these to register to the reference one and I would like to understand what goes wrong here.
Thank you!
L.
0 Commenti
Risposte (1)
Matt J
il 4 Set 2024
Modificato: Matt J
il 4 Set 2024
Perhaps as follows,
load Images
g=@(z) entropyfilt(z); f=@(z) z.*(z>=1.5);
im=f(g(im));
ref=f(g(ref));
ov=imref2d(size(im));
[optimizer, metric] = imregconfig('multimodal');
transform = imregtform(im,ov,ref,ov, 'translation', optimizer, metric,'DisplayOptimization',0);
[optimizer, metric] = imregconfig('monomodal');
transform = imregtform(im,ov,ref,ov, 'affine', optimizer, metric,...
'DisplayOptimization',0,Initial=transform);
load Images
reg = imwarp(im,transform,'cubic','FillValues',1,'OutputView',ov);
subplot(1,3,1)
imshow(ref,[]); title 'Reference'
subplot(1,3,2)
imshow(reg,[]); title 'Registered'
subplot(1,3,3)
imshow(imfuse(reg,ref,'diff')); title 'Fuse'
h=gcf; h.Position(3:4)=[903 188];
4 Commenti
Matt J
il 6 Set 2024
Modificato: Matt J
il 7 Set 2024
But I don't understand why is the registration so unreliable with such similar images.
From the point of view of most registration algorithms, the images are only "similar" if there is strong overlap between where image features are positioned in the moving and reference images. That is less and less the case as the image frames progress. The objects in the scene become significantly displaced from the reference image and overlap diminishes greatly. On top of that, you have edge truncation effects, and also differences and unevenness in illumination across frames.
Below, I have yet another variant which is working for me on the 18-frame movie that you sent, but it relies on the assumption that there will always be only incremental change in the image position from one frame to the next. If you continue to have problems, you could try backing off from an affine transform in the refinement step to a similarity transform (I wonder if you really need more than that). With fewer degrees of freedom in the transformation model, the registration will be more stable.
load data.mat
reference = data(:,:,1);
images = data(:,:,2:end);
[H,W,N]=size(images);
imagesfilt=preproc(images);
referencefilt = preproc(reference);
registeredVolume=nan(H,W,N);
tform0=transltform2d;
for i = 1:N
disp(['Registering image ', num2str(i),' of ', num2str(N)]);
image=images(:,:,i);
imagefilt = imagesfilt(:,:,i);
%Similarity-only registration and warping
ov = imref2d(size(image));
[optimizer, metric] = imregconfig('multimodal');
tform0 = imregtform(imagefilt,ov,referencefilt,ov, 'translation', ...
optimizer, metric,'DisplayOptimization',0,Initial=tform0);
%Form an intermediate image by warping. Fill black areas with ones.
tmp = imwarp(image,tform0,'cubic','FillValues',0,'OutputView',ov);
tmp(tmp<0.5)=1;
registeredVolume(:,:,i) = tmp;
%Refine with a full affine registration
[optimizer, metric] = imregconfig('multimodal');
tform1 = imregtform(preproc(tmp),ov,referencefilt,ov,...
'affine', optimizer, metric,'DisplayOptimization',0);
transform=affinetform2d(tform1.A*tform0.A);
registered = imwarp(image,transform,'cubic','FillValues',1,'OutputView',ov);
registered(registered<0.5)=1;
registeredVolume(:,:,i) = registered;
end
close all
for i = [1,3:3:N]
registered=registeredVolume(:,:,i);
image=images(:,:,i);
figure(i);
subplot(1,3,1); imshow(reference,[0.9,1.1]); title 'Target';
subplot(1,3,2); imshow(registered,[0.9,1.1]); title 'Registered';
subplot(1,3,3); imshow(imfuse(registered,reference,'diff'),[]); title 'Diff After';
end
function Inew=preproc(I)
Inew = 1000*(1-I);
Inew=Inew.*(abs(Inew)<=50);
end
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!