Generate an indexed image
조회 수: 16 (최근 30일)
이전 댓글 표시
Claudia Lucia Silva Olvera
2021년 12월 1일
댓글: Claudia Lucia Silva Olvera
2021년 12월 1일
How do I create an indexed image to import into Matlab?. Thanks
댓글 수: 0
채택된 답변
Image Analyst
2021년 12월 1일
Try this:
% Demo by Image Analyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
markerSize = 40;
% Read in original RGB image and display it.
originalImage = imread('peppers.png');
subplot(2, 1, 1);
imshow(originalImage);
impixelinfo;
title('Original Image', 'FontSize', fontSize)
% Create indexed image with 6 colors.
numColors = 6;
[indexedImage, cmap] = rgb2ind(originalImage, numColors);
% Save it to disk.
imwrite(indexedImage, cmap, 'indexedImage.png');
% Read indexed image back in from disk.
[recalledImage, storedColorMap] = imread('indexedImage.png');
% Display it.
subplot(2, 1, 2);
imshow(recalledImage, 'Colormap', storedColorMap);
caption = sprintf('Indexed Image with %d Colors', numColors);
title(caption, 'FontSize', fontSize)
% Display color bar and adjust range from 0-255 to 0-numColors.
colorbar;
caxis([0, numColors])
impixelinfo;
% Maximize figure window.
g = gcf;
g.WindowState = 'maximized';
댓글 수: 0
추가 답변 (1개)
Benjamin Kraus
2021년 12월 1일
Are you trying to create an indexed image in MATLAB? Or are you asking what programs (aside from MATLAB) can be used to create indexed image?
Some resources that may help:
If those links don't help, I think you are going to need to add a lot more detail to your question to get a helpful answer.
댓글 수: 3
Benjamin Kraus
2021년 12월 1일
Aside from using MATLAB itself to read in an image and transform it into an indexed image (MATLAB can read and write indexed and non-indexed images), I'm not familiar with what other image editing programs can be used to do that.
Why do you need to transform an image into an indexed image before reading it into MATLAB? Why not just read it directly into MATLAB?
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!