Extracting a range of pixel values from a specific RGB band?

3 visualizaciones (últimos 30 días)
I am trying to extract all pixels that are in the range 128 - 256 of the green band on an RGB TIFF. I can create a mask, but when I try to get an image with just these pixels I end up with a binary image, but I want to see all the pixels within my range.
This is what I've done:
>> I = imread(fullfile('D:\MatLab_Practice', 'RGB.tif'));
>> green = I(:,:,2);
>> imhist(green)
>> mask = green > 127; %(I have also tried the roicolor(green,128,256) to create a mask with same results)
>> G1 = double(green);
>> G2 = G1 .* mask;
if I use imhist(G2) I don't see the values I want, but using histogram(G2) I see everything I don't want as zero and and the range of values I need. But when trying to view my image I still only get a binary black and white image.
Any advice on how to proceed?

Respuesta aceptada

Emma Tompkins
Emma Tompkins el 24 de Oct. de 2017
NEVERMIND figured it out!
need to convert mask to integer and then multiply by the original green band
>> I = imread(fullfile('D:\MatLab_Practice', 'RGB.tif'));
>> green = I(:,:,2);
>> imhist(green)
>> mask = green > 127; %(I have also tried the roicolor(green,128,256) to create a mask with same results)
>> mask = uint8(mask); %to match the same data type as image
>> G2 = green .* mask;

Más respuestas (0)

Categorías

Más información sobre Author Block Masks en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by