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 comentarios

Jan
Jan el 23 de Nov. de 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 el 23 de Nov. de 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....
Walter Roberson
Walter Roberson el 23 de Nov. de 2011
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 el 24 de Nov. de 2011
@Walter Roberson Please give me an example so that I can write code easily
Walter Roberson
Walter Roberson el 24 de Nov. de 2011
You have not clearly indicated what it is that you want to do, so I cannot provide sample code.

Iniciar sesión para comentar.

 Respuesta aceptada

Image Analyst
Image Analyst el 24 de Nov. de 2011

2 votos

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 comentarios

Nick ALan
Nick ALan el 28 de Nov. de 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.
Walter Roberson
Walter Roberson el 28 de Nov. de 2011
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 el 29 de Nov. de 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.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 24 de Nov. de 2011

1 voto

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 comentarios

Nick ALan
Nick ALan el 24 de Nov. de 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....
Walter Roberson
Walter Roberson el 24 de Nov. de 2011
imcrop()
rbbox()
ginput()
Image Analyst
Image Analyst el 24 de Nov. de 2011
See my code in another Answer.

Iniciar sesión para comentar.

Categorías

Más información sobre Convert Image Type en Centro de ayuda y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by