Crop or resize image

Hi,
This is nick.I want to select a pixels of different sizes from a figure which is obtained from the matlab.Let me know how to select it by a example.
Thank you

5 Comments

Jan
Jan on 23 Nov 2011
Please select a meaningful title for the question - *all* questions in this forum concern Matlab.
Then define the inputs exactly - what kind of figures are you talking of? Could you show us an example?
Which tool do you want to use and what the wnated outputs?
Nick ALan
Nick ALan on 23 Nov 2011
I had pictures of format .jpeg or.png or .fig.The size of picture is 1024*1024.But I have to select small pixel size of 100*100....
You need to divide the image in to blocks that size? If so, blockproc or blkproc or mat2cell.
You need to resize the image to 100 x 100 ? If so, imresize()
Nick ALan
Nick ALan on 24 Nov 2011
@Walter Roberson Please give me an example so that I can write code easily
You have not clearly indicated what it is that you want to do, so I cannot provide sample code.

Sign in to comment.

 Accepted Answer

Nick:
Try this demo:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'cameraman.tif';
fullFileName = fullfile(folder, baseFileName);
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
message = sprintf('Draw a box');
uiwait(msgbox(message));
k = waitforbuttonpress;
point1 = get(gca,'CurrentPoint'); % button down detected
finalRect = rbbox; % return figure units
point2 = get(gca,'CurrentPoint'); % button up detected
point1 = point1(1,1:2); % extract x and y
point2 = point2(1,1:2);
p1 = min(point1,point2); % calculate locations
offset = abs(point1-point2); % and dimensions
x = round([p1(1) p1(1)+offset(1) p1(1)+offset(1) p1(1) p1(1)])
y = round([p1(2) p1(2) p1(2)+offset(2) p1(2)+offset(2) p1(2)]);
hold on
axis manual
plot(x,y)
croppedImage = grayImage(y(1):y(3), x(1):x(2));
% Display the cropped gray scale image.
subplot(2, 2, 2);
imshow(croppedImage, []);
title('Cropped Image', 'FontSize', fontSize);
% Make them color images.
% Use the jet colormap
rgbCroppedImage =uint8(255 * ind2rgb(croppedImage, jet));
% Display the colorized cropped gray scale image.
subplot(2, 2, 3);
imshow(rgbCroppedImage, []);
title('Colorized Cropped Image', 'FontSize', fontSize);
% Make the original image color.
rgbImage = cat(3, grayImage, grayImage, grayImage);
% Insert the colored portion:
rgbImage(y(1):y(3), x(1):x(2), :) = rgbCroppedImage;
% Display the colored gray scale image.
subplot(2, 2, 4);
imshow(rgbImage, []);
title('Colorized Cropped Image Inserted', 'FontSize', fontSize);

3 Comments

Nick ALan
Nick ALan on 28 Nov 2011
@ Image Analyst Thanks for your help.This is very helpful to me.But for my task I have to select the pixel of 100*100 or 10*10 from the original one.
Nick, we still need you to explain clearly what you mean by "select the pixel of 100*100 or 10*10". If you mean that you need to select a 100 by 100 or 10 by 10 area on the image, then just modify Image Analyst's code to only read input coordinate (e.g., using ginput) and to assume that the 100 by 100 (or 10 by 10) extends in a particular direction (e.g., up and right from the chosen point.)
Nick ALan
Nick ALan on 29 Nov 2011
@walter Roberson ya,thats right.I want to select the pixel of 100 by 100 or 10 by 10 and extend it up.At what point in the code i had to apply ginput.modify the code and help me to get out of this.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 24 Nov 2011

1 vote

Nick: All pixels are the same size. Why don't you post an image at your favorite file hosting web site (one where I don't have to do a ton of clicks to see your image - try tinypic.com)? Then tell us what you need to measure in that image. In the meantime, see my BlobsDemo for a tutorial on measuring objects in an image http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862

3 Comments

Nick ALan
Nick ALan on 24 Nov 2011
@ Image Analyst Attached is the picture of some Basalt example.I think the actual pixel size is 1011*1230.I want to select a some part of it(pixel of size 100*100) and I wanted to apply colormap to it.
http://i39.tinypic.com/wtho5j.jpg....
imcrop()
rbbox()
ginput()
See my code in another Answer.

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!