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

3 次查看(过去 30 天)
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?

采纳的回答

Emma Tompkins
Emma Tompkins 2017-10-24
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;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Author Block Masks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by