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

6 visualizaciones (últimos 30 días)
rachana
rachana el 19 de Sept. de 2012
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 comentarios
rachana
rachana el 21 de Sept. de 2012
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 el 21 de Sept. de 2012
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.

Iniciar sesión para comentar.

Respuestas (2)

Image Analyst
Image Analyst el 19 de Sept. de 2012
Editada: Image Analyst el 19 de Sept. de 2012
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 comentarios
rachana
rachana el 21 de Sept. de 2012
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 el 21 de Sept. de 2012
Editada: Image Analyst el 21 de Sept. de 2012
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);

Iniciar sesión para comentar.


Jan
Jan el 19 de Sept. de 2012
[Img, Map] = rgb2ind(RGB, 256);

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by