Filter löschen
Filter löschen

How to crop 4 different images from a single image?

1 Ansicht (letzte 30 Tage)
Prashant
Prashant am 17 Feb. 2014
Kommentiert: Prashant am 18 Feb. 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?

Akzeptierte Antwort

Image Analyst
Image Analyst am 17 Feb. 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 Kommentare
Image Analyst
Image Analyst am 17 Feb. 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 am 18 Feb. 2014
Thanks...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Code Generation, GPU, and Third-Party Support finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by