資源簡介
使用歸一化相關(guān)函數(shù)進行配準,Step 1: Read Images,
%Step 2: Choose Subregions of Each Image,Step 3: Do Normalized Cross-correlation and Find Coordinates of Peak。。。。。。

代碼片段和文件信息
%使用歸一化相關(guān)函數(shù)進行配準
%Step?1:?Read?Images
lily?=?imread(‘lily.tif‘);
flowers?=?imread(‘flowers.tif‘);
figure?imshow(lily)
figure?imshow(flowers)???
%Step?2:?Choose?Subregions?of?Each?Image?
%?non-interactively
rect_lily?=?[93?13?81?69];
rect_flowers?=?[190?68?235?210];
sub_lily?=?imcrop(lilyrect_lily);
sub_flowers?=?imcrop(flowersrect_flowers);
%?OR?
???
%?interactively
%?[sub_lilyrect_lily]?=?imcrop(lily);?%?choose?one?petal?of?lily
%?[sub_flowersrect_flowers]?=?imcrop(flowers);?%?choose?whole?lily
%?display?sub?images
figure?imshow(sub_lily)
figure?imshow(sub_flowers)???
%Step?3:?Do?Normalized?Cross-correlation?and?Find?Coordinates?of?Peak
c?=?normxcorr2(sub_lily(::1)sub_flowers(::1));
figure?surf(c)?shading?flat
%Step?4:?Find?the?Total?Offset?Between?the?Images
%?offset?found?by?correlation
[max_c?imax]?=?max(abs(c(:)));
[ypeak?xpeak]?=?ind2sub(size(c)imax(1));
%?corr_offset?=?[(xpeak-size(sub_lily2))?
%????????????????(ypeak-size(sub_lily1))];
%相關(guān)運算,參考點為模板右下角(因為進行了翻轉(zhuǎn)),實際參考點應(yīng)該為模板左上角
corr_offset?=?[(xpeak-size(sub_lily2)+1)?
???????????????(ypeak-size(sub_lily1)+1)];
%?relative?offset?of?position?of?subimages
rect_offset?=?[(rect_flowers(1)-rect_lily(1))?
???????????????(rect_flowers(2)-rect_lily(2))];
%?total?offset
offset?=?corr_offset?+?rect_offset;
xoffset?=?offset(1);
yoffset?=?offset(2);
%Step?5:?See?if?the?Image?Lily?Was?Extracted?from?the?Image?Flowers?
%?xbegin?=?xoffset+1;
%?xend???=?xoffset+?size(lily2);
%?ybegin?=?yoffset+1;
%?yend???=?yoffset+size(lily1);
%此時偏移點已經(jīng)是圖像左上角
xbegin?=?xoffset;
xend???=?xoffset+?size(lily2)-1;
ybegin?=?yoffset;
yend???=?yoffset+size(lily1)-1;
%?extract?region?from?flowers?and?compare?to?lily
extracted_lily?=?flowers(ybegin:yendxbegin:xend:);
if?isequal(lilyextracted_lily)?
???disp(‘lily.tif?was?extracted?from?flowers.tif‘)
end
%Step?6:?Pad?the?Lily?Image?to?the?Size?of?the?Flowers?Image
recovered_lily?=?uint8(zeros(size(flowers)));
recovered_lily(ybegin:yendxbegin:xend:)?=?lily;
figure?imshow(recovered_lily)
%Step?7:?Transparently?Overlay?Lily?Image?on?Flowers?Image
[mnp]?=?size(flowers);
mask?=?ones(mn);?
i?=?find(recovered_lily(::1)==0);
mask(i)?=?.2;?%?try?experimenting?with?different?levels?of?transparency
%?overlay?images?with?transparency
figure?imshow(flowers(::1))?%?show?only?red?plane?of?flowers
hold?on
h?=?imshow(recovered_lily);?%?overlay?recovered_lily
set(h‘AlphaData‘mask)
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2556??2005-04-18?17:28??nccr.m
-----------?---------??----------?-----??----
?????????????????2556????????????????????1
評論
共有 條評論