taking part of the picture
18 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Akzeptierte Antwort
Harshit
am 26 Nov. 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 Kommentare
Weitere Antworten (1)
Image Analyst
am 26 Nov. 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 Kommentare
Image Analyst
am 27 Nov. 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);
Siehe auch
Kategorien
Mehr zu Explore and Edit Images with Image Viewer App finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!