When using imread, changed the background colour of image?

I had an image of a red cross with a background colour of white, after I used imread, it returned an image with a black background. Why is this? And, does it have anything to with the file format? (.png) This is messing with the entire program.

Answers (1)

Extract the color channels and see what the values are
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
Then pick a row and column that's in the background and see what they are
r = redChannel(row, column)
g = greenChannel (row, column)
b = blueChannel (row, column)
Tell us what your values are.

3 Comments

It says 0, 0, 0 for red, blue and green channels. This is black, right? And after imread when I use imshow, it shows the original red cross but with a black background. Also, I saw this thing on imread, you define a three member vector with each member a value between 0 and 1, and say
>> BG = [0 0 1]; >>I1 = imread('red cross.png','BackgroundColor',BG);
When I put BG as 1 1 1, it shows up with a white background. But this doesn't explain why the colours should be inverted from the original image in the first place.
If it's a uint8 image, the values should be integers going from 0 to 255. If you have a double image (floating point) then all values must be in the range 0-1 if you want to display them with imshow(). [0,0,0] is pure black. [0,0,1] is pure blue. [1,1,1] is pure white. Any transparent pixels in your PNG image will show up in the "BG" color. Maybe your background is not really transparent like you thought.
This makes sense, because when I try the same thing (setting the background color for another image), it gives an error.

Sign in to comment.

Categories

Tags

Asked:

on 14 Jul 2013

Community Treasure Hunt

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

Start Hunting!