Borrar filtros
Borrar filtros

taking part of the picture

14 visualizaciones (últimos 30 días)
eman
eman el 25 de Nov. de 2012
Hi;
I'm newbie in mat lab and I've a picture that I need to cut or delete the bottom region of it and I've used this cod it makes error I do not know why and how can i take a portion of this picture and not all of it.
Here is the code:
ROI= imread('pic.jpg');
imfinfo('pic.jpg');%to know the number of columns and number of rows
nRows=1180;
nColumns=2039;
%Region Of Interest exclude the bottom part
% ROI=imresize(ROI,[nRows nColumns]);
ROI=ROI(1:1180,:);
imshow('pic.pg')
Thanks in advance

Respuesta aceptada

Harshit
Harshit el 26 de Nov. de 2012
Here is an error you can't use imshow on an image. You have to first read it in a variable then use imshow on that. imshow(ROI) is the correct answer
  4 comentarios
Harshit
Harshit el 27 de Nov. de 2012
Sorry I agree image analyst point is correct.
eman
eman el 27 de Nov. de 2012
Thanks Image Analyst,Thanks Harshit I have accepted Harshit answer because when I changed the code from
imshow('pic.jpg') TO
imshow(ROI)
a figure has showed up
about what I'm saying my comment,I need to take a portion from the picture not whole the picture then I am going to use sobel edge detection. when the program ran it showed a figure with 3 copies of the original picture.
I hope that I clarify my problem.
Thanks again ,I hope you can help me.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 26 de Nov. de 2012
You need to show your ROI variable, not some bad filename. You put pic.pg, not pic.jpg, so that doesn't exist, but anyway, even if a file by that name existed, that will display the full file, not a cropped portion of it. You should do it this way:
grayImage = imread('pic.jpg');
croppedImage = grayImage(1:1180, :);
imshow(croppedImage);
  3 comentarios
Image Analyst
Image Analyst el 27 de Nov. de 2012
I find that hard to believe. Here, run this demo and see if it works:
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.
format longg;
format compact;
fontSize = 20;
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'concordorthophoto.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- 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 in the search path folders.', 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(1, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Crop off the first 1180 lines and display that:
croppedImage = grayImage(1:1180, :);
[rows2 columns2 numberOfColorBands2] = size(croppedImage)
subplot(1, 2, 2);
imshow(croppedImage, []);
title('Cropped Grayscale Image', 'FontSize', fontSize);
eman
eman el 30 de Nov. de 2012
Thanks too much it works will.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by