From: normad on
im sorry if this is a noob question but i cant seem to get around
it..

im using imread() to read a boolean png file where certain parts of it
are black..and my intention is to convert the black parts into another
color.. for this i tried using

ind2rgb(imread('name.png','png'),[1 0 0]);

when i do that instead of converting black parts to red the whole
image goes red.

please help.. thanks in advance
From: ImageAnalyst on
You need to pass in an N by 3 color map. Since you just passed in [1
0 0], you're saying that no matter what gray level you pass in, you
want it mapped to pure red. Try it like in this demo instead:

clc;
clear all;
close all;
workspace;

% Read in standard MATLAB demo image.
grayImage = imread('cameraman.tif');
subplot(1, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image');
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.

% Set up a colormap that will color gray level 13 as pure red.
cmap = gray; % Default - no color applied.
cmap(14,:) = [1 0 0]; % Maps gray level of 13 to red.
% Set up the range 175 - 255 to be green.
cmap(176:256,:) = repmat([0 1 0], [81 1]);

% Apply the color map to the monochrome image to produce an rgb color
image.
coloredImage = ind2rgb(grayImage, cmap);

% Display it.
subplot(1, 2, 2);
imshow(coloredImage, []);
title('Colorized Image');
From: normad on
Thanks a lot.. that fixed the problem!! :)