Error while changing image bit depth in MATLAB

조회 수: 4 (최근 30일)
Chethan
Chethan 2013년 6월 5일
I'm trying to convert RGB image with some bit depth to BMP image of bit depth 8. here is my code
a = imread('DSC01684_5.bmp');
[x,map] = rgb2ind(a,32);
imwrite(x,map,'C:\Documents and Settings\Home\Desktop \DSC01684_5.bmp.','bitdepth', 8);
and I'm getting error like
??? Error using ==> imformats>find_in_registry at 507
Format specifier must be a 1-D character array.
Error in ==> imformats at 114
varargout{1} = find_in_registry(fmts, varargin{1});
Error in ==> imwrite>get_format_from_filename at 550
fmt_s = imformats(ext);
Error in ==> imwrite at 389
format = get_format_from_filename(filename);
is the error in imwrite function or in changing bit depth?
However if i use
output_filename = 'C:\Documents and Settings\Home\Desktop\DSC01684_5.bmp.'
imwrite(x, map, output_filename, 'bmp', 'bitdepth', 8);
I'm getting error like
??? Error using ==> imagesci\private\writebmp
Too many input arguments
Error in ==> imwrite at 429
feval(fmt_s.write, data, map, filename, paramPairs{:});

채택된 답변

Jan
Jan 2013년 6월 5일
편집: Jan 2013년 6월 5일
The first error is caused by the trailing dot in "DSC01684_5.bmp.", such that omitting it allows to recognize the file type by the extension.
Because RGB2IND replies an UINT8 for 32 colors, you do not have to specify the bitdepth explicitly:
file = 'C:\Documents and Settings\Home\Desktop\DSC01684_5.bmp'
imwrite(x, map, file);
imfinfo(file)
% >> ... BitDepth: 8

추가 답변 (1개)

Walter Roberson
Walter Roberson 2013년 6월 5일
'bitdepth' only applies to JPEG and PNG formats. There are no supported options for bmp files.
  댓글 수: 2
Chethan
Chethan 2013년 6월 6일
편집: Walter Roberson 2013년 6월 6일
Please check this image http://s1273.photobucket.com/user/Chethan_tv/media/DSC00947_zps342d216d.png.html This image is 8 bit and BMP format
Walter Roberson
Walter Roberson 2013년 6월 6일
imwrite() chooses the depth from the datatype in this situation. It only allows that automatic depth choice to be overridden via the 'bitdepth' option for JPEG and PNG

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by