首页 > 代码库 > matlab学习笔记,图像分块

matlab学习笔记,图像分块

clc; clear all; close all;
I = imread(‘E:\matlab\files-images\tomsen512.jpg‘);

rs = size(I, 1);% 行数
cs = size(I, 2); % 列数
% ch为列间隔 cw为行间隔 ,控制分块图像的大小,如现在的8*8
% numr为间隔块个数 numc为间隔块个数
ch = 8;   
cw = 8;
numr = round(rs/ch);
numc = round(cs/cw);
% 区域块分割
t1 = (0:numr-1)*ch + 1; t2 = (1:numr)*ch;
t3 = (0:numc-1)*cw + 1; t4 = (1:numc)*cw;

figure; imshow(I); hold on;

for i=1:numr
    for j=1:numc
        x=t1(i):t2(i);
        y=t3(j):t4(j);
        rectangle (‘Position‘, [t3(j) t1(i) length(x) length(y)], ...,
            ‘EdgeColor‘, ‘r‘, ‘LineWidth‘, 1); %绘制矩形分割格子,红色
    end
end

效果如图,亲测可用(密集恐惧症慎点):

技术分享

 

matlab学习笔记,图像分块