how to convert a 24 bit image to 8 bit image? what functions to use?
조회 수: 8 (최근 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
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
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
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);
참고 항목
카테고리
Help Center 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!