matlab实现对图像的切割
发表时间:2020-10-19
发布人:葵宇科技
浏览次数:50
在有些法度榜样中因为图像过大年夜,经常须要我们将图像切割成就个比较小的图案之后在进行相干的处理。
Img=imread('sssd.png'); imgsize=size(Img) subimg_width=600; subimg_height=1000; num_width_spilt=ceil(imgsize(1)/subimg_width); num_height_spilt=ceil(imgsize(2)/subimg_height); num=num_width_spilt*num_height_spilt; for i=1:num_width_spilt for j=1:num_height_spilt if(i*subimg_width<=imgsize(1)) width=subimg_width; else width=imgsize(1)-(i-1)*subimg_width; end if(j*subimg_height<=imgsize(2)) height=subimg_height; else height=imgsize(2)-(j-1)*subimg_height; end subimg=zeros(width,height); for ii=1:width for jj=1:height for kk=1:3 subimg(ii,jj,kk)=Img((i-1)*subimg_width+ii,(j-1)*subimg_height+jj,kk); end end end subimg=uint8(subimg); eval(['imwrite(subimg, ''subimg' num2str((i-1)*num_width_spilt+j) '.bmp'',''bmp'');']); end end对下图进行瓜分,获得四个小图
[img]http://img.blog.csdn.net/20150105102301202?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhvdXllbGlodWE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
获得的四个小图:
第一张:
[img]http://img.blog.csdn.net/20150105102337703?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhvdXllbGlodWE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
第二张
[img]http://img.blog.csdn.net/20150105102451557?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhvdXllbGlodWE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
第三张:
[img]http://img.blog.csdn.net/20150105102542849?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhvdXllbGlodWE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
第四┞放
[img]http://img.blog.csdn.net/20150105102543437?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhvdXllbGlodWE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center