Split one image into multiple images
显示 更早的评论
I have 1 image size 10x10 like this:
image = [ 0 0 1 1 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0
0 1 1 1 0 0 0 1 1 1
0 1 1 1 0 0 0 1 1 0
0 1 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0 ]
I want to split this image into many other images, like:
I1 = [ 0 0 1 1 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 ]
I2 = [ 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0
0 1 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 ]
...and so on. Each splited image contains 1 part of feature of the origin.
I tried to find local but the result wasn't as expected
[y_peaks x_peaks] = find(image);
np = 1;
for ii=1:length(y_peaks)-1
if ((y_peaks(ii+1)==(y_peaks(ii)-1))&&((x_peaks(ii+1)==(x_peaks(ii)-1))))||...
((y_peaks(ii+1)==(y_peaks(ii)-1))&&((x_peaks(ii+1)==(x_peaks(ii)+0))))||...
((y_peaks(ii+1)==(y_peaks(ii)-1))&&((x_peaks(ii+1)==(x_peaks(ii)+1))))||...
((y_peaks(ii+1)==(y_peaks(ii)+0))&&((x_peaks(ii+1)==(x_peaks(ii)-1))))||...
((y_peaks(ii+1)==(y_peaks(ii)+0))&&((x_peaks(ii+1)==(x_peaks(ii)+1))))||...
((y_peaks(ii+1)==(y_peaks(ii)+1))&&((x_peaks(ii+1)==(x_peaks(ii)-1))))||...
((y_peaks(ii+1)==(y_peaks(ii)+1))&&((x_peaks(ii+1)==(x_peaks(ii)+0))))||...
((y_peaks(ii+1)==(y_peaks(ii)+1))&&((x_peaks(ii+1)==(x_peaks(ii)+1))))
local_y(ii,np) = y_peaks(ii);
local_x(ii,np) = x_peaks(ii);
local_y(ii+1,np) = y_peaks(ii+1);
local_x(ii+1,np) = x_peaks(ii+1);
else
np = np + 1;
local_y(ii+1,np) = y_peaks(ii+1);
local_x(ii+1,np) = x_peaks(ii+1);
end
end
采纳的回答
更多回答(1 个)
binaryImage = [ 0 0 1 1 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0
0 1 1 1 0 0 0 1 1 1
0 1 1 1 0 0 0 1 1 0
0 1 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0 ]
[labeledImage, numRegions] = bwlabel(binaryImage); % Identify (label) each individual blob.
subplot(numRegions+1, 1, 1);
imshow(binaryImage); % Display original image.
title('Original image')
% Create individual images and display them.
for k = 1 : numRegions
thisImage = ismember(labeledImage, k); % Create image.
subplot(numRegions+1, 1, k+1);
imshow(thisImage); % Display this image.
end
See my Image Processing Tutorial:
类别
在 帮助中心 和 File Exchange 中查找有关 Image Arithmetic 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
