i have two different images for the same wall , i want to combine both so the second one will be placed in the proper place over the first image as shown below. any idea which code shall i use ?,i used many all converts the images to Gray.
<<
<<
.

7 Comments

i am trying to use
imfuse(A,Ir); imshow(ans);
but i am getting image like attached, how i can make it colored ?
I don't think you can. imfuse() just puts images into different color channels. You'd have to find the overlap region and compute the average there, and in non overlap regions, compute the sum.
A = imread('1.jpg');
B = imread('2.jpg');
original=rgb2gray(A)
distorted=rgb2gray(B)
ptsOriginal = detectSURFFeatures(original);
ptsDistorted = detectSURFFeatures(distorted);
[featuresOriginal,validPtsOriginal] = ...
extractFeatures(original,ptsOriginal);
[featuresDistorted,validPtsDistorted] = ...
extractFeatures(distorted,ptsDistorted);
index_pairs = matchFeatures(featuresOriginal,featuresDistorted);
matchedPtsOriginal = validPtsOriginal(index_pairs(:,1));
matchedPtsDistorted = validPtsDistorted(index_pairs(:,2));
figure;
showMatchedFeatures(original,distorted,...
matchedPtsOriginal,matchedPtsDistorted);
title('Matched SURF points,including outliers');
[tform,inlierPtsDistorted,inlierPtsOriginal] = ...
estimateGeometricTransform(matchedPtsDistorted,matchedPtsOriginal,...
'similarity');
figure;
showMatchedFeatures(original,distorted,...
inlierPtsOriginal,inlierPtsDistorted);
title('Matched inlier points');
outputView = imref2d(size(original));
Ir = imwarp(B,tform,'OutputView',outputView);
figure; imshow(Ir);
title('Recovered image');
saveas(gcf,'t_img4.jpg')
imwrite(Ir,'3.png');
this is the last code i used and i got this one
so i dont know which code shall i use now
Michal Dobai
Michal Dobai on 11 Dec 2017
Edited: Michal Dobai on 11 Dec 2017
* this comment was changed to answer *
Thanks Michal - this was more work than I was planning on putting into it, so he's lucky you did it. Why don't you put this down in the answers section so you can get credit for you?
first thanks for the help , sorry i did a mistake with the uploading this is image 1
and this is the final result after applying the code from Michal Dobai

Sign in to comment.

 Accepted Answer

This is answer to your comment .
Problem with your code is, that you display only registered image (Ir). As Image Analyst suggested , you should first combine image A with registered image Ir.
So instead of:
figure; imshow(Ir);
you should do something like this:
% Calculate mask of images 1.jpg and 2.jpg
% (for this example, let's say that 'outside' black pixels are
% background pixels)
maskA = imfill(original ~= 0, 'holes');
maskB = imfill(rgb2gray(Ir) ~= 0, 'holes');
% Mask area where these 2 pictures overlap
overlapMask = maskA & maskB;
% ...and extend it to 3 dimensional RGB image
overlapMaskRGB = cat(3, overlapMask, overlapMask, overlapMask);
% Now, as Image Analyst suggested, sum pixels in non overlap regions
% and in overlap regions, compute the average value.
% You can, for example, sum both images, and in overlaped area divide it by 2
C = A+Ir;
C(overlapMaskRGB) = C(overlapMaskRGB)/2;
figure;
imshow(C);
Result image is attached below. Now, as you can see, there is a little problem around the edges. (there are some dark pixels). That is because in this example we 'assume' that background of your input images is completely black (that means pixel values [0 0 0]). It doesn't have to be always true, especially for JPEG images, because of the compression artifacts.
You can use one of the image formats with lossless compression (for example png) for better results, or you can set the threshold and mask pixels darker than this threshold.

1 Comment

i have two different hazy images for the same scence i want to fused these two images which code shall i use ?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!