how to make hsv converted image two dimensional?
Mostrar comentarios más antiguos
I have converted an image to hsv image...now i need to find the edges by using canny.But while doing i am getting an error...
Error using ==> iptcheckinput Function EDGE expected its first input, I, to be two-dimensional.
Error in ==> edge>parse_inputs at 541 iptcheckinput(I,{'numeric','logical'},{'nonsparse','2d'},mfilename,'I',1);
Error in ==> edge at 197 [a,method,thresh,sigma,thinning,H,kx,ky] = parse_inputs(varargin{:});
Error in ==> mergealgo at 37 im_canny = edge(inputgray, 'canny');
how to make hsv image two dimensional?
1 comentario
Image Analyst
el 19 de Abr. de 2012
Is inputgray the Value channel? inputgray=hsvImage(:,:,3)????
Respuesta aceptada
Más respuestas (2)
Image Analyst
el 20 de Abr. de 2012
My guess is that the "inputgray" image is still a 3D RGB image, or else the 3D HSV image. What does this say when you put it in?
[rows columns numberOfColorChannels] = size(inputgray)
It should tell you the sizes/dimensions in the command window. Here's code for a working demo using the standard MATLAB peppers color image.
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 = 16;
% Read in a standard MATLAB color demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'peppers.png';
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
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows columns numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(2, 4, 1);
imshow(rgbImage, []);
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Get HSV color space version of the image
hsv = rgb2hsv(rgbImage);
h = hsv(:, :, 1);
s = hsv(:, :, 2);
v = hsv(:, :, 3);
% Display the images.
subplot(2, 4, 2);
imshow(h, []);
title('Hue Image', 'FontSize', fontSize);
subplot(2, 4, 3);
imshow(s, []);
title('Saturation Image', 'FontSize', fontSize);% Display the images.
subplot(2, 4, 4);
imshow(v, []);
title('Value Image', 'FontSize', fontSize);
% Run Canny Edge on them all
hEdge = edge(h, 'canny');
sEdge = edge(s, 'canny');
vEdge = edge(v, 'canny');
% Display the images.
subplot(2, 4, 6);
imshow(hEdge, []);
title('Hue Edge Image', 'FontSize', fontSize);
subplot(2, 4, 7);
imshow(sEdge, []);
title('Saturation Edge Image', 'FontSize', fontSize);% Display the images.
subplot(2, 4, 8);
imshow(vEdge, []);
title('Value Edge Image', 'FontSize', fontSize);
2 comentarios
vysakh
el 20 de Abr. de 2012
Image Analyst
el 20 de Abr. de 2012
And what do you think I did? Did you even run this demo I made for you???
Walter Roberson
el 20 de Abr. de 2012
0 votos
There is no 2 dimensional equivalent to an hsv image.
The closest you can get is to use the hsv equivalent of pseudo-color images -- to create a 2 dimensional array in which each value is the index of an HSV tuple in a map.
You can create such a thing by applying rgb2ind() to the HSV array (rgb2ind() will not notice that the data is actually HSV.)
I warn, however, that the canny edge detector will likely have very poor performance on mapped images. The index numbers that are used in mapping do not have any relationship to each other: index #83 might refer to a color that is extremely different than index #84.
If working on one of the individual channels, H, S, or V, does not work for you, then converting to a mapped HSV image and doing the edge detection on that will almost certainly be much worse.
But you can always try it if you need to prove to yourself that a "2 dimensional HSV image" is the wrong thing to use.
Categorías
Más información sobre Convert Image Type en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!