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

6 ビュー (過去 30 日間)
Amr Azab
Amr Azab 2022 年 7 月 28 日
コメント済み: Amr Azab 2022 年 8 月 2 日
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;
%Read Photo RGB and DSM
orph = imread('BE_ORTHO_27032011_315145_56865.tif');
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
Walter Roberson 2022 年 7 月 28 日
[r, c, p] = size(orph);
mask_building = createMask(roi_Building, r, c);
building_pixels = [op_red(mask_building), op_green(mask_building), op_blue(mask_building)];
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);
mask3_building = repmat(createMask(roi_Building, r, c), [1, 1, 3]);
masked_building = zeros(r, c, p, 'like', orph);
masked_building(mask3_building) = orph(mask3_building);
which would create a new imae masked_building in which the pixels that are not inside the ROI are all set to 0 (black)
  8 件のコメント
Walter Roberson
Walter Roberson 2022 年 8 月 2 日
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
Amr Azab 2022 年 8 月 2 日
Thank you Mr Walter

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by