图像切割matlab程序

clc;
clear all;
[pathname,filename] = uigetfile('*.*','选择图片','E:\裂纹\NG2裂纹\');
src_path =strcat(filename,pathname) ;
dst_path = 'E:\学习资料\MATLAB程序\裂纹分割\';
if ~exist('E:\学习资料\MATLAB程序\裂纹分割\')
    mkdir('E:\学习资料\MATLAB程序\裂纹分割\');
end

A = imread(src_path);
figure;
imshow(A);
[m,n,l] = size(A);
a = 8;
figure;
for i = 1:a
    for j = 1:a
    m_start = 1+ (i-1)*fix(m/a);
    m_end = i*fix(m/a);
    n_start = 1+ (j-1)*fix(m/a) ;
    n_end = j*fix(n/a);
    AA = A(m_start:m_end,n_start:n_end,:);
    imwrite(AA,[dst_path num2str(i) '_' num2str(j) '.jpg'],'jpg');
    subplot(8,8,(i-1)*8+j);
    imshow(AA);
    hold on;
    end
end

图像切割matlab程序_第1张图片

原图:

图像切割matlab程序_第2张图片

你可能感兴趣的:(图像切割)