"uncollage" a collage image
16 ビュー (過去 30 日間)
古いコメントを表示
Hi,
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/147451/image.jpeg)
so I can save all the images it contains in separate files?
I wish to automate this process so I can use it with a collage image composed of X images. What I am thinking to do is to detect the rectangular shape coordinates so I can crop the image using them but how can I do it?
Any other ideas are welcome. Thanks
0 件のコメント
採用された回答
Image Analyst
2013 年 4 月 26 日
See my Image Segmentation Tutorial: http://www.mathworks.com/matlabcentral/fileexchange/25157-image-segmentation-tutorial-blobsdemo. It will show you how you can threshold objects on a dark background and crop out their bounding box to separate images. Almost exactly what you want to do, except that you have color images. Basically you want to extract the color channels:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
Then create a binary image:
binaryImage = redChannel == 0 & greenChannel == 0 & blueChannel == 0;
Then label pass it into regionprops
blobMeasurements = regionprops(binaryImage, 'BoundingBox');
Then use a loop that for each region, use imcrop() to extract the bounding box from the original rgb image and use imwrite() to save it to a disk file. Here's the relevant code from my tutorial, which I'm sure a smart guy like you can modify - just take out the stuff about what coin type it is, and add a call to imwrite().
message = sprintf('Would you like to crop out each coin to individual images?');
reply = questdlg(message, 'Extract Individual Images?', 'Yes', 'No', 'Yes');
% Note: reply will = '' for Upper right X, 'Yes' for Yes, and 'No' for No.
if strcmpi(reply, 'Yes')
figure;
% Maximize the figure window.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
for k = 1 : numberOfBlobs % Loop through all blobs.
% Find the bounding box of each blob.
thisBlobsBoundingBox = blobMeasurements(k).BoundingBox; % Get list of pixels in current blob.
% Extract out this coin into it's own image.
subImage = imcrop(originalImage, thisBlobsBoundingBox);
% Determine if it's a dime (small) or a nickel (large coin).
if blobMeasurements(k).Area > 2200
coinType = 'nickel';
else
coinType = 'dime';
end
% Display the image with informative caption.
subplot(3, 4, k);
imshow(subImage);
caption = sprintf('Coin #%d is a %s.\nDiameter = %.1f pixels\nArea = %d pixels', ...
k, coinType, blobECD(k), blobMeasurements(k).Area);
title(caption, 'FontSize', 14);
end
0 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!