声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2699|回复: 4

[求助]matlab图象处理的问题

[复制链接]
发表于 2006-1-7 13:14 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
<P>我没学过matlab,但最近需要用到下面这个程序,对于一些语句的功能我不太懂,你各位高手赐教,不胜感激!!!!<BR>onion = imread('onion.png');<BR>peppers = imread('peppers.png');</P>
<P>imshow(onion)<BR>figure, imshow(peppers)</P>
<P><BR>% non-interactively<BR>rect_onion = [111 33 65 58];<BR>rect_peppers = [163 47 143 151];<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><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>
回复
分享到:

使用道具 举报

 楼主| 发表于 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>
发表于 2006-1-7 13:52 | 显示全部楼层

回复:(Blackeye)[求助]matlab图象处理的问题(图形...

<DIV class=quote><B>以下是引用<I>Blackeye</I>在2006-1-7 13:41:23的发言:</B><BR>
<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>请问能否确定读出图片的区域值??<BR><BR><BR><FONT color=#ff0000>imread读入的时候就已经确定大小了,矩阵的大小表示的就是图片的大小,比如:</FONT></STRONG><BR><FONT color=#ff0000>onion = imread('onion.png');<BR>[m n k]=size(inion);<BR>则m表示纵向的像素点数,n表示横向的像素点数</FONT><BR></P>
<P><BR>% non-interactively<BR>rect_onion = [111 33 65 58];<BR>rect_peppers = [163 47 143 151];<STRONG>怎么确定要剪切的图片的区域范围??<BR><BR><FONT color=#ff0000>这个要看你自己的要求,你要去哪一部分就选取哪一部分</FONT><BR><BR><BR></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>后面的好多语句不知道什么意思,恳请各位高手将每句注释一下,谢谢!!<BR><BR><FONT color=#ff0000>请说明具体那些语句</FONT><BR><BR></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></DIV>
<br>
 楼主| 发表于 2006-1-7 15:19 | 显示全部楼层

多谢您的指导,我还有下面这些语句的功能不清楚,请赐教~~~

(1)  c = normxcorr2(sub_onion(:,:,1),sub_peppers(:,:,1));<BR>normxcorr2是实现什么功能??(:,:,1)是什么参数??<BR><BR>以下也大多是一些函数的功能不知道<BR>(2)[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))];<BR><BR>谢谢!!!<BR><BR>(3)<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<BR><BR>
发表于 2006-1-7 17:51 | 显示全部楼层

回复:(Blackeye)多谢您的指导,我还有下面这些语句...

<DIV class=quote><B>以下是引用<I>Blackeye</I>在2006-1-7 15:19:08的发言:</B><BR>(1)  c = normxcorr2(sub_onion(:,:,1),sub_peppers(:,:,1));<BR>normxcorr2是实现什么功能??(:,:,1)是什么参数??<BR><BR>以下也大多是一些函数的功能不知道<BR>(2)[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))];<BR><BR>谢谢!!!<BR><BR>(3)<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<BR><BR></DIV>
<br><BR><BR>help 或者 doc自己啊
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-26 05:25 , Processed in 0.063240 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表