MATLAB Answers


how to cropt the image and save cropped part

Asked by andhavarapu lokesh on 5 Dec 2016
Latest activity Commented on by Image Analyst
on 18 Aug 2018
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
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');
hFH = imfreehand();
% Create a binary image ("mask") from the ROI object.
binaryImage = hFH.createMask();


Sign in to comment.

1 Answer

Answer by KSSV
on 5 Dec 2016

I = imread('cameraman.tif');
[I2, rect] = imcrop(I);
imshow(I2) ;
Extract the part you want, say it is I2. Using imwrite you can write the mage you want.


Thanks for helping. I got it.
how could u solve it, sir ? if u don't mind for sharing it
The code I gave was this.
for k = 1 : size(BB, 1)
face = imcrop(img, BB(k, :));
% subplot(6, 6, k);
thisFileName = sprintf('Face #%d.png', k);
fullFileName = fullfile(pwd, thisFileName);
imwrite(face, fullFileName);
You'll see it if you click the "Show older comments" link above.

Sign in to comment.