Borrar filtros
Borrar filtros

How to crop 4 different images from a single image?

1 visualización (últimos 30 días)
Prashant
Prashant el 17 de Feb. de 2014
Comentada: Prashant el 18 de Feb. de 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?

Respuesta aceptada

Image Analyst
Image Analyst el 17 de Feb. de 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 comentarios
Image Analyst
Image Analyst el 17 de Feb. de 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 el 18 de Feb. de 2014
Thanks...

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Code Generation, GPU, and Third-Party Support en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by