1. 程式人生 > >基於Matlab的影象分塊處理

基於Matlab的影象分塊處理

簡介
在影象處理中,影象塊操作是常用的操作之一。這裡介紹一種分塊方法。

例項

clc; clear all; close all;
A = imread('cameraman.tif');
info = imfinfo('cameraman.tif');
wd = info.Width;
hd = info.Height;
num = 8;
sub_wd = wd / num;
sub_hd = hd / num;
if ndims(A) == 3
    B=rgb2gray(A);%把真彩圖轉換為灰度圖
else
    B = A;
end
B=im2double(B);
C=mat2cell(B, num*ones(1, sub_wd), num*ones(1, sub_hd));
D=reshape(C,1,[]);
for k = 1 : length(D)
    E{k}=reshape(D{k},[],1);
end
%把畫素轉化為1列64行的矩陣

----------------------------------------------------------------------------

clc; clear all; close all;
I = imread('cameraman.tif');
sz = size(I);
[x, y] = meshgrid(1:15:sz(2), 1:15:sz(1));
z = ones(size(x));
figure('units', 'normalized', 'position', [0 0 1 1], ...
    'color', [55,190,254]/255);
imshow(I, []);
hold on; axis off;
mesh(x, y, z, 'FaceColor', 'none', ...
    'EdgeColor', 'r', 'LineWidth', 2, ...
    'Marker', 'o', 'MarkerFaceColor', 'k', ...
    'MarkerSize', 5);

結果