Effacer les filtres
Effacer les filtres

How to crop 4 different images from a single image?

1 vue (au cours des 30 derniers jours)
Prashant
Prashant le 17 Fév 2014
Commenté : Prashant le 18 Fév 2014
I have a form with 4 image fields, stacked together horizontally, I want to crop these 4 images automatically, and want to save these 4 images individually with 4 different file names. How could I perform it using Matlab. Can you help me with some code for it?

Réponse acceptée

Image Analyst
Image Analyst le 17 Fév 2014
[rows, columns, numberOfColorChannels] = size(theImage);
col4 = round(columns/4, columns/2, 3*columns/4);
if numberOfColorChannels == 1
% Gray scale image.
image1 = theImage(:, 1:col4(1));
image2 = theImage(:, col4(1)+1:col4(2));
image3 = theImage(:, col4(2)+1:col4(3));
image4 = theImage(:, col4(3)+1:end);
else
% Color image.
image1 = theImage(:, 1:col4(1), :);
image2 = theImage(:, col4(1)+1:col4(2), :);
image3 = theImage(:, col4(2)+1:col4(3), :);
image4 = theImage(:, col4(3)+1:end, :);
end
Then use imwrite to save each quadrant.
  2 commentaires
Image Analyst
Image Analyst le 17 Fév 2014
OK, with that image, you need to threshold it
binaryImage = grayImage < 128;
and then skeltonize the image with bwmorph,
binaryImage = bwmorph(binaryImage, 'skel', inf);
extract a line half way down and find the middle line and use find() to figure out where the vertical lines are.
lineLocations = find(binaryImage(rows/2,:));
Then use those columns to extract the images like I did above. Let me know if you still can't figure it out.
Prashant
Prashant le 18 Fév 2014
Thanks...

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Code Generation, GPU, and Third-Party Support dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by