how to convert a 24 bit image to 8 bit image? what functions to use?

7 次查看(过去 30 天)
i want to convert a 24 bit normal image to 8 bit image. so that i can perform edge detection on it. also if u have any psuedo-code or functions for 24 bit image edge detection please let me know
  3 个评论
rachana
rachana 2012-9-21
Right now i am working on the gray scale image of lenadark (8 bit,bmp). But in my project of edge detection i have to use color image(24bit,jpeg), convert it to gray scale image of (8 bit). Another question I want to ask is, can matlab work with .jpeg images directly?
Walter Roberson
Walter Roberson 2012-9-21
MATLAB cannot work with .jpeg files directly, as far as I know.
There are some facilities in blockproc() to work with large TIFF files, but I do not know how to invoke them.

请先登录,再进行评论。

回答(2 个)

Image Analyst
Image Analyst 2012-9-19
编辑:Image Analyst 2012-9-19
Have you tried rgb2gray() or edge()?
Edges in color won't necesarily carry through to the monochrome version of the image. There are edge detection algorithms what work with the color image. Where did you upload your image, so we can see it?
  2 个评论
rachana
rachana 2012-9-21
Thanku sir! I havent actually uploaded any image, but right now I am working on lenadark(8bit, bmp). And my interest lies in converting our real time images(which are of 24bit, jpeg format) of color to gray scale.
Image Analyst
Image Analyst 2012-9-21
编辑:Image Analyst 2012-9-21
Well, that's the whole purpose of rgb2gray(), though the speed may not meet your needs of "real time" depending on how large your image is. Also you need to be aware that the grayscale image that rgb2ind gives you is not a grayscale image like you'd think of it. Looking at it will not give you anything recognizable in grayscale. You cannot do image processing on an indexed image returned by rgb2ind(). It only looks good when the colormap is applied to give a pseudocolored image. Run this code to understand why:
clc;
clearvars;
close all;
imtool close all; % Close all imtool figures.
workspace;
format longg;
format compact;
fontSize = 16;
% Read in a standard MATLAB color demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'peppers.png';
% 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, 2, 1);
imshow(rgbImage, []);
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Create gray scale image with rgb2gray:
grayImage = rgb2gray(rgbImage);
subplot(2, 2, 2);
imshow(grayImage, [0 255]);
title('converted with rgb2gray()', 'FontSize', fontSize);
% Create gray scale image with rgb2ind:
[indexedImage, Map] = rgb2ind(rgbImage, 256);
subplot(2, 2, 3);
imshow(indexedImage, []);
title('converted with rgb2ind()', 'FontSize', fontSize);
promptMessage = sprintf('Now we will apply the color map to all gray scale images.');
titleBarCaption = 'Apply color map?';
button = questdlg(promptMessage, titleBarCaption, 'OK', 'Cancel', 'OK');
if strcmp(button, 'Cancel')
return;
end
colormap(Map);

请先登录,再进行评论。


Jan
Jan 2012-9-19
[Img, Map] = rgb2ind(RGB, 256);

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by