matlab图像均匀分割

这是在指导本科生毕业设计的过程中,想到的一个方法,可以为以后遥感图像的处理做铺垫: 

 
用matlab给图像分块并保存 - 露沙 - 成淀于深
 
 
[FileName,PathName] = uigetfile('*.*','Select the image');  
Im=imread([PathName FileName]);
imshow(Im)
hold on
L = size(Im);
height=160;
width=160;
max_row = floor(L(1)/height);%实验图片为800*1280,则max_row=5,max_col=8
max_col = floor(L(2)/width);
seg = cell(max_row,max_col);
%分块
for row = 1:max_row      
    for col = 1:max_col        
    seg(row,col)= {Im((row-1)*height+1:row*height,(col-1)*width+1:col*width,:)};   
    end
end 
for i=1:max_row*max_col
imwrite(seg{i},strcat('m',int2str(i),'.bmp'));   %把第i帧的图片写为'mi.bmp'保存
end
%画出分块的边界
for row = 1:max_row      
    for col = 1:max_col  
 rectangle('Position',[160*(col-1),160*(row-1),160,160],...
         'LineWidth',2,'LineStyle','-','EdgeColor','r');
        end
end 
hold off


复杂版本,考虑了重叠和边界不完整部分,请参考
http://gzc828.blog.163.com/blog/static/104123664201331190646/

猜你喜欢

转载自blog.csdn.net/sinat_36420785/article/details/73742049