请指导我分割图像

时间:2019-07-19 07:20:49

标签: matlab image-processing

我想将图像分为三个部分,这是我尝试过的:

[filename pathname]=uigetfile('*.png','Pick the image file');
file=strcat(pathname,filename);
I=imread(file);
figure,imshow(I);
title('Input Image');
im1=I;
su=median(im1);
median=ceil(su);
[row, col]=size(I);
%mr = median(row/2); % median of rows
mc = median(col/3); % median of columns
right = I(1:mr  , (mc+1):col);
figure,imshow(right)

我希望这可以将图像分为三部分,但可以分为右上和左上并创建镜像

这是我需要分为三部分的图片,但应该是单张图片:

example image

1 个答案:

答案 0 :(得分:0)

您可以使用mat2cell将图像拆分为所需的任意数量:

img = imread('https://i.stack.imgur.com/s4wAt.png');
[h w c] = size(img);
numSplits = 3;  % how many splits you want
sw = floor(w/numSplits);  % width of split 
widths = repmat(sw, 1, numSplits-1);
widths(numSplits) = w - sum(widths);  % last one is bit wider if width does not divide
splits = mat2cell(img, h, widths, c);  % this splits the image

% show the splits
for ii=1:numSplits 
   subplot(1,numSplits,ii);
   imshow(splits{ii});
end

结果与
enter image description here