# How can I know the value of pixel "ROI" in each (RGB) Channel?

6 views (last 30 days)
Amr Azab on 28 Jul 2022
Commented: Amr Azab on 2 Aug 2022
I hope someone can help me out.
I have 4 ROI Buildings, Cars, Street and Trees and each one has defined but what i need to know, How can i get the Values of pixels of ROI in each channel in RGB image (Red, Green and Blue)?
Please tell me exactly, the code, that i should write!
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
% CleanUp
clc;
clear;
close all;
figure, imshow (orph,[]);
%Define Region of interest
roi_Building = drawpolygon('Color','r');
roi_Street = drawline('Color','y');
roi_Tree = drawfreehand('Color','g');
roi_car = drawpolygon('Color','b');
%Seperate channels RGB
op_red= orph(:,:,1); % Red channel
op_green= orph(:,:,2); % Green channel
op_blue= orph(:,:,3); % Blue channel
%Value of pixels in all layers

Walter Roberson on 28 Jul 2022
[r, c, p] = size(orph);
This would be N x 3 where N is the number of selected pixels, and the columns are R, G, B.
But I wonder if what you would prefer would instead be
[r, c, p] = size(orph);
masked_building = zeros(r, c, p, 'like', orph);
which would create a new imae masked_building in which the pixels that are not inside the ROI are all set to 0 (black)
Amr Azab on 2 Aug 2022
Thank you Mr Walter

### Categories

Find more on Blocked Images in Help Center and File Exchange

R2021a

### Community Treasure Hunt

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

Start Hunting!