how to cropt the image and save cropped part

조회 수: 48 (최근 30일)
andhavarapu lokesh
andhavarapu lokesh 2016년 12월 5일
댓글: Walter Roberson 2021년 3월 12일
i have an image i wanted to crop a part of the image and save the cropped part as image can any one help me for cropping and saving the image
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
clc; % Clear command window.
clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
imtool close all; % Close all figure windows created by imtool.
workspace; % Make sure the workspace panel is showing.
fontSize = 16;
% Read in standard MATLAB gray scale demo image.
grayImage = imread('cameraman.tif');
subplot(2, 3, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
message = sprintf('Left click and hold to begin drawing.\nSimply lift the mouse button to finish');
uiwait(msgbox(message));
hFH = imfreehand();
% Create a binary image ("mask") from the ROI object.
binaryImage = hFH.createMask();

답변 (2개)

KSSV
KSSV 2016년 12월 5일
I = imread('cameraman.tif');
[I2, rect] = imcrop(I);
imshow(I2) ;
imwrite(I2,'Example.jpg')
Extract the part you want, say it is I2. Using imwrite you can write the mage you want.
  댓글 수: 8
Ade Aulya
Ade Aulya 2018년 8월 18일
how could u solve it, sir ? if u don't mind for sharing it
Image Analyst
Image Analyst 2018년 8월 18일
The code I gave was this.
for k = 1 : size(BB, 1)
face = imcrop(img, BB(k, :));
figure;
% subplot(6, 6, k);
imshow(face);
drawnow;
thisFileName = sprintf('Face #%d.png', k);
fullFileName = fullfile(pwd, thisFileName);
imwrite(face, fullFileName);
end
You'll see it if you click the "Show older comments" link above.

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


Aytaç Tok
Aytaç Tok 2021년 3월 7일
Hello there. I want to get an object in the rgb picture, how can I do that. For example, there is a banana on the table and the background is black. How can I get only the banana picture from the picture. ı dont want to take by boundingbox. I must take with border coordinates because ı need just object.There should be no background in the picture I'm waiting for your help.pleaseeee
  댓글 수: 6
Aytaç Tok
Aytaç Tok 2021년 3월 10일
The background is a problem because I will take only the banana object in this picture and operate on it.
Walter Roberson
Walter Roberson 2021년 3월 12일
You cannot do that. The closest you can get is
with all of the boundary taken out. But you cannot get rid of the black part to the lower left, for example, because doing so would involve creating a "ragged" array where those black pixels literally do not exist even though pixels above or to their right exist.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by