Cut a sub-region in image

조회 수: 5 (최근 30일)
Rooter Boy
Rooter Boy 2021년 2월 8일
댓글: Image Analyst 2021년 2월 10일
Question: Read the 1024x1024 image named "sar.jpg" in Matlab and assign it to the "img" variable. It is aimed to cut a sub-region in this image. Using the values given in the table, write the Matlab code that will create this sub-region that will be of (m, n) size starting from (x, y) point. Write the codes that show this area on the screen and save it in the file.
My tried code:
img = imread('sar.jpg');
img2 = imcrop(I,[234 210 191 130]);
subplot(1,2,1)
imshow(img)
title('orginal image')
subplot(1,2,2)
imshow(img2)
title('Cutting image')
I think, my tried code is not true. If someone help me, i will be very happy.
  댓글 수: 3
Rooter Boy
Rooter Boy 2021년 2월 8일
I don't understand, so i am not sure. Is this what is required in the question?
Matt J
Matt J 2021년 2월 8일
Looks fine to me.

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

채택된 답변

Image Analyst
Image Analyst 2021년 2월 8일
You need to pass img into imcrop(), not I, and you need to subtract 1 from the sizes because of the way imcrop works. You can also do it by indexing. Here is the fixed code:
img = imread('peppers.png');
whos img
img2 = imcrop(img,[234 210 190 129]);
whos img2
img3 = img(210: (210 + 129), 234 : (234 + 190), :);
whos img3
subplot(1,2,1)
imshow(img)
title('Original Image')
subplot(1,2,2)
imshow(img2)
title('Cropped Image')
  댓글 수: 2
Rooter Boy
Rooter Boy 2021년 2월 9일
Sir, i need a full code, "Write the codes that show this area on the screen and save it in the file." How to coded in this case.
Image Analyst
Image Analyst 2021년 2월 10일
I'm sure you've solved it by now, but use imwrite():
fileName = 'Cropped Image.png'; % Whatever you want.
imwrite(img2, fileName); % Write to disk.
And obviously the imshow() does the "show this area on the screen" part of your assignment.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by