From: normad on 12 Jan 2010 12:59 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 12 Jan 2010 13:21 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 12 Jan 2010 21:27 Thanks a lot.. that fixed the problem!! :)
|
Pages: 1 Prev: Access to bertool through an m file Next: superellipsoid |