Reputation: 864
I have a logical image. I want to convert black pixels to other colours.
I can convert them to black green and blue but I do not know how can I convert them other colours like orange, purple, pink...
Is there any way to make this?
I convert them to blue using this code
RGB = zeros(3072, 4080, 1);
RGB(:, :, 3) = 1-BW;
imshow(RGB);
Best regards
Upvotes: 1
Views: 1284
Reputation: 114786
You probably want to use ind2rgb
that converts 2D matrix of indexes (index-image) to RGB image according to a specific colormap
Let r
, g
and b
be three double values (in range [0..1]) representing the new color you wish to assign to pixels for which BW
is false
then
RGB = ind2rgb( BW, [ r, g, b; 1 1 1] );
converts all black to [r,g,b]
and leave the true
pixels white.
here's an example:
BW = rand(10) < .5;
RGB = ind2rgb( BW, [100/255 10/255 50/255; 1 1 1]);
figure;
imshow( RGB );
And the result should be (up to randomness of BW
):
Upvotes: 0
Reputation: 2366
Maybe this FEX code might help - Color brewer. Depending on the color you chose in the color brewer webpage, the function will give the representation in MATLAB. All you have do is to use these numbers to represent individual pixels.
Upvotes: 0
Reputation: 221504
Code
BW = logical(round(rand(5,6))) %// random logical image as input for demo
color1 = [129 52 168]; %// random color to be superimposed on the black pixels
%// Create a 3D double array with zeros from BW replaced by color1 values
%// and ones by zeros
RGB1 = bsxfun(@times,double(~BW),permute(color1,[1 3 2]));
%// Replace the zeros created from the previous step to 255s, as they
%// denote ones in the input logical image
RGB = uint8(RGB1+(RGB1==0).*255); %// desired output RGB image in UINT8 format
imagesc(RGB),axis off %// display the RGB image for verification
Output (on code run)
BW =
1 0 1 1 0 1
0 0 1 0 0 1
0 1 1 1 1 0
0 0 1 1 1 1
0 1 0 0 0 0
Hope this would work for you! Let me know.
Upvotes: 0
Reputation: 469
To get non primary colours, you need to edit the values of more than one of the layers of colours - each pixel is made up of red, green and blue subpixels (Hence RGB). Basically you need to find the combination of intensities to make your colours up.
If you wanted to set the colour as bright yellow, the following should work:
RGB(:, :, 3) = blue_intensity;
RGB(:, :, 2) = green_intensity;
As yellow in light is made from blue and green. if you want more of one colour than the other, simply make one intensity number higher than the other.
If you post exactly what you are trying to achieve, i can post a clearer answer.
Also i believe your fist line should read RGB = zeros(3072, 4080, 3);
, making a 3d vector, 3 deep, as is appropriate for an RGB image
Upvotes: 1