Find image pixels linked to a specific color in its colormap

6 Ansichten (letzte 30 Tage)
Hi. I need to find which pixels in an image are linked to a specific colour of its colormap. I have one RGBA image that, when importing with imread(), I get the image (m-by-n matrix) and its colourmap (r-by-3). I know I can do it using find() function (like in the code bellow) but I would like to know if there is another way? Maybe a manual way that I can find the pixels linked to that specific colour/range of colours in the map?
[I,map] = imread('image.png'); % 'I' is represented in uint8 and 'map' in double
find(I==1) %Considering that the pixels I want to find are the ones represented by the colour (1,1,1) in the colormap
Thanks!

Akzeptierte Antwort

Leonardo Alves
Leonardo Alves am 23 Mai 2020
So, after a lot of searching and reading I found a way of how to find the pixels linked to every colour of colormap. Based on that I can do a manual search for a specific colour.
Solution:
[I,map] = imread('image.png'); % 'I' is represented in uint8 and 'map' in double
figure
imshow(A,map); %Plot the image and its colormap
colorbar; %Show the colormap in the plot
ax = gca;
spectData = ax.Children.CData; %Generate a matrix (m-by-n) with the color in each pixel
Based on that I can now use loops or any other function instead of find() to find the pixels required based on its colour.

Weitere Antworten (0)

Kategorien

Mehr zu Color and Styling finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by