|
楼主 |
发表于 2006-1-7 13:41
|
显示全部楼层
[求助]matlab图象处理的问题(图形简切与恢复)
<DIV class=quote>
<P><STRONG>我没学过matlab,但最近需要用到下面这个程序,对于一些语句的功能我不太懂,你各位高手赐教,不胜感激!!!!<BR></STRONG>onion = imread('onion.png');<BR>peppers = imread('peppers.png');</P>
<P>imshow(onion)<BR>figure, imshow(peppers)<STRONG>请问能否确定读出图片的区域值??</STRONG></P>
<P><BR>% non-interactively<BR>rect_onion = [111 33 65 58];<BR>rect_peppers = [163 47 143 151];<STRONG>怎么确定要剪切的图片的区域范围??</STRONG><BR>sub_onion = imcrop(onion,rect_onion);<BR>sub_peppers = imcrop(peppers,rect_peppers);</P>
<P>% OR</P>
<P>% interactively<BR>%[sub_onion,rect_onion] = imcrop(onion); % choose the pepper below the </P>
<P>onion<BR>%[sub_peppers,rect_peppers] = imcrop(peppers); % choose the whole onion</P>
<P>% display sub images<BR>figure, imshow(sub_onion)<BR>figure, imshow(sub_peppers)</P>
<P><STRONG>后面的好多语句不知道什么意思,恳请各位高手将每句注释一下,谢谢!!</STRONG><BR>c = normxcorr2(sub_onion(:,:,1),sub_peppers(:,:,1));<BR>figure, surf(c), shading flat</P>
<P><BR>% offset found by correlation<BR>[max_c, imax] = max(abs(c(:)));<BR>[ypeak, xpeak] = ind2sub(size(c),imax(1));<BR>corr_offset = [(xpeak-size(sub_onion,2))<BR> (ypeak-size(sub_onion,1))];</P>
<P>% relative offset of position of subimages<BR>rect_offset = [(rect_peppers(1)-rect_onion(1))<BR> (rect_peppers(2)-rect_onion(2))];</P>
<P>% total offset<BR>offset = corr_offset + rect_offset;<BR>xoffset = offset(1);<BR>yoffset = offset(2);</P>
<P>xbegin = round(xoffset+1);<BR>xend = round(xoffset+ size(onion,2));<BR>ybegin = round(yoffset+1);<BR>yend = round(yoffset+size(onion,1));</P>
<P>% extract region from peppers and compare to onion<BR>extracted_onion = peppers(ybegin:yend,xbegin:xend,:);<BR>if isequal(onion,extracted_onion)<BR> disp('onion.png was extracted from peppers.png')<BR>end</P>
<P><BR>recovered_onion = uint8(zeros(size(peppers)));<BR>recovered_onion(ybegin:yend,xbegin:xend,:) = onion;<BR>figure, imshow(recovered_onion)</P>
<P><BR>[m,n,p] = size(peppers);<BR>mask = ones(m,n);<BR>i = find(recovered_onion(:,:,1)==0);<BR>mask(i) = .2; % try experimenting with different levels of<BR> % transparency</P>
<P>% overlay images with transparency<BR>figure, imshow(peppers(:,:,1)) % show only red plane of peppers<BR>hold on<BR>h = imshow(recovered_onion); % overlay recovered_onion<BR>set(h,'AlphaData',mask)</P></DIV>
<br> |
|