interpretation of imread output array values

hi, I'm trying to use imread to get an array representation of an image, then search that array for places where a specific colour occurs. I can't seem to find any doumentation on how the double, presented in the array, represents the colour at that location. How do I know which number represents which colour so that i can search for it?

7 Kommentare

Stephen23
Stephen23 am 22 Feb. 2023
Bearbeitet: Stephen23 am 22 Feb. 2023
"I can't seem to find any doumentation on how the double, presented in the array, represents the colour at that location."
Depnding on the image file, those values could be grayscale lightness values, or RGB channel values, or indices into a colormap. So far you have not given us sufficient information to know which of these you are working with.
thanks, its a colour .jpg file. Not sure how to tell if it's indexed to a colormap but I think most likely not. Thanks for the links, I'll read through them and educate myself
DGM
DGM am 22 Feb. 2023
Bearbeitet: DGM am 22 Feb. 2023
If it's a color JPG and it's readable by imread(), it's RGB and not indexed color. It's more than likely uint8, so each element will be within the interval [0 255].
As to what "a specific color" means, that's up to your needs to define.
If you want to inspect the image to get an idea of the tuples that represent a pixel or the pixels in a region, you can use impixel() or impixelinfo(), or you can always use a datatip. There are also color picker tools on the File Exchange.
If you want to create a logical mask describing the extent of colored objects/regions in an image, you want to look for information about color-based segmentation. There are many examples on the forum, and IPT has the Color Thresholder app which may make it easier to get started.
Does any of that sound like where you're trying to go with this? If so, it would help to have a representative example of the image(s) and a description of the goals.
Stephen23
Stephen23 am 22 Feb. 2023
"If it's a color JPG and it's readable by imread(), it's RGB and not indexed color."
IMREAD also imports indexed images. Its second output argument is the corresponding colormap:
DGM
DGM am 22 Feb. 2023
True, but imread() doesn't support indexed images in JPG or JP2.
I'm kind of assuming that imread() would complain if you tried to feed it an indexed JP2, but I don't have one to test.
Stephen23
Stephen23 am 22 Feb. 2023
"True, but imread() doesn't support indexed images in JPG or JP2."
Could you please show a reference to indexed JPG and JP2 image formats.
I do not see how spatial image compression using frequencies/wavelets could be indexed.
DGM
DGM am 22 Feb. 2023
Bearbeitet: DGM am 22 Feb. 2023
It doesn't make sense to me either, and likewise, I can't find any mention of such a thing existing
... except the statement from the webdocs:
Indexed JPEG 2000 images are not supported. Only JP2 compatible color spaces are supported for JP2/JPX files. By default, all image channels are returned in the order they are stored in the file.
Which seems to suggest that maybe there exist some non-compliant files that are indexed. I don't know why else they'd point out that imread() can't read such a thing.
Even if this is all just a poorly-worded comment about being incompatible with things that don't exist, I tried to to phrase my original statement to be safe either way.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Timothy Dunning
Timothy Dunning am 22 Feb. 2023

0 Stimmen

The file is an RGB .jpg and it produces a 3D array where each value is a uint8 in the range 0-255 representing the rgb colour scale. Thanks for the help.

Weitere Antworten (0)

Kategorien

Mehr zu Convert Image Type finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by