how to convert a 24 bit image to 8 bit image? what functions to use?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Walter Roberson
am 21 Sep. 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.
Antworten (2)
Image Analyst
am 19 Sep. 2012
Bearbeitet: Image Analyst
am 19 Sep. 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 Kommentare
Image Analyst
am 21 Sep. 2012
Bearbeitet: Image Analyst
am 21 Sep. 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);
Siehe auch
Kategorien
Mehr zu Convert Image Type finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!