필터 지우기
필터 지우기

How to crop 4 different images from a single image?

조회 수: 1 (최근 30일)
Prashant
Prashant 2014년 2월 17일
댓글: Prashant 2014년 2월 18일
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?

채택된 답변

Image Analyst
Image Analyst 2014년 2월 17일
[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
Image Analyst
Image Analyst 2014년 2월 17일
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 2014년 2월 18일
Thanks...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Code Generation, GPU, and Third-Party Support에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by