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

23 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)
Walter Roberson on 2 Aug 2022
Class_mean1 = size(AVG_BU);
You are taking the size() of the averages. Notice that in each case the size is 1 x 3, so the Class variables are each the two element vectors [1, 3]
Di_Building = sqrt((orph(:,:,1)-Class_mean1(1,1)).^2 + (orph(:,:,2)-Class_mean1(2,1)).^2 + (orph(:,:,3)-Class_mean1(3,1)).^2);
You index the 1 x 2 vector of size information at up to index (3,1) but the row vector of size information does not have 3 rows.
I suggest that you want to be subtracting AVG_BU(1) AVG_BU(2) AVG_BU(3)
Amr Azab on 2 Aug 2022
Thank you Mr Walter

### Categories

Find more on Object Detection 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!