Undefined function 'rgb2gray' : Error using image function
6 次查看(过去 30 天)
显示 更早的评论
Hi all, I am new to Matlab and have student version R2012a. I am trying to convert a color image to black and white. The error and code is listed below.
I appreciate all your help
Regards,
Amit Bothra
Error:
Undefined function 'rgb2gray' for input arguments of type 'uint8'.
Error in Week09_Program1 (line 4) Abw = rgb2gray(A);
My code:
clear all; close all; clc; A = imread('chacha','jpg'); size(A); Abw = rgb2gray(A);
1 个评论
Jan
2013-1-31
编辑:Jan
2013-1-31
Btw, omitting the "clear all" is a good idea, because there is no reason to remove all loaded functions from the memory. I assume, anywhere in the universe there is a dwarfish and evil teacher, who instructs the pupils to use clear all, most of all when posting code in a forum, to test when I desperate and give up mentioning this trivial but important detail.
@evil dwarfish teacher: I will be stronger!
@frequent contributors: Sorry that I repeat myself such frequently. It is not my intention to annoy you. I only want to save energy.
I wait for the day when a user finds out, that the code runs faster with this modification:
all = 7.0710678; % <- magic accelerator!
clear all
...
回答(2 个)
Image Analyst
2013-1-30
Type "ver" on the command line in the command window. Do you see the Image Processing Toolbox listed? Or you can run this code:
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
2 个评论
Image Analyst
2013-1-31
You do not have the Image Processing Toolbox so you don't have the rgb2gray() function. You can use the formula Jan gave as a replacement.
Jan
2013-1-30
编辑:Jan
2013-1-30
If you do not have the Image Processing Toolbox, you find e.g. this in the FileExchange: http://www.mathworks.de/matlabcentral/fileexchange/29392-rgb2gray.
But when you are in the net already, why not asking your favorite internet serach engine? You find even more useful source codes. E.g.:
GrayImg = uint8(0.2989 * Img(:,:,1) + 0.5870 * Img(:,:,2) + ...
0.1140 * Img(:,:,3));
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!