How do I convert gray or indexed images to color images?

2 ビュー (過去 30 日間)
fereshte
fereshte 2014 年 5 月 24 日
編集済み: Image Analyst 2014 年 5 月 24 日
Hi. I applied The following code to resize my images. The input images are color images. But as an output, the resized images are gray! How do I correct it?

採用された回答

Image Analyst
Image Analyst 2014 年 5 月 24 日
That image is a 2D image, an indexed image with a color map. It's not a 3D color RGB image. You need to convert it to an RGB image if you recognize it's an indexed image. Replace your loop with this:
for k = 1:numel(bmpFiles)
fullInputFileName = fullfile(inputFolder,bmpFiles(k).name)
[originalImage, colorMap] = imread(fullInputFileName);
[rows, columns, numberOfColorChannels] = size(originalImage)
if ~isempty(colorMap) && numberOfColorChannels == 1
% It's an indexed image with a colormap.
% Convert it to RGB color
originalImage = ind2rgb(originalImage, colorMap);
[rows, columns, numberOfColorChannels] = size(originalImage)
end
fullOutputFileName = fullfile(outputFolder, bmpFiles(k).name);
outputImage = imresize(originalImage, [100,50]);
[rows columns numberOfColorChannels] = size(outputImage);
if numberOfColorChannels == 1
% It's monochrome, so convert to color.
outputImage = cat(3, outputImage, outputImage, outputImage);
end
figure,imshow(outputImage);
imwrite(outputImage, fullOutputFileName);
end
  1 件のコメント
fereshte
fereshte 2014 年 5 月 24 日
wow.its great.dear Image Analyst thank you so much.good luck

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRed についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by