Two ROI in one image and calculate mean for each ROI

2 次查看(过去 30 天)
From the image I want to extract to sepearte regions(area inside red ribbon), for both the regions i want to find mean.
I have tried the code of @ImageAnalyst, where i can draw the ROI and find mean.
but I want my code to automatically detect the rois and give sepearte means.

采纳的回答

Simon Chan
Simon Chan 2022-3-1
You may try the following:
clear; clc;
rawdata = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/910580/@60%20visi.png');
[R,G,B] = imsplit(rawdata);
maskR = R>180 & R<260;
maskG = G>60 & G<140;
maskB = B>110 & B<190;
BW1 = maskR & maskG & maskB;
SE = strel('square',20);
BW2 = imclose(BW1,SE) | BW1;
BW2 = bwareafilt(BW2,2); % Optional, Just make sure 2 largest ROIs are selected
BW3 = bwlabel(imclearborder(~BW2),4);
figure
subplot(3,2,1)
imshow(R.*uint8(BW3==1));
title(sprintf('Red Channel Mean: ROI#1: %.2f',mean(R(BW3==1))));
subplot(3,2,2)
imshow(R.*uint8(BW3==2));
title(sprintf('Red Channel Mean: ROI#2: %.2f',mean(R(BW3==2))));
%
subplot(3,2,3)
imshow(G.*uint8(BW3==1));
title(sprintf('Green Channel Mean: ROI#1: %.2f',mean(G(BW3==1))));
subplot(3,2,4)
imshow(G.*uint8(BW3==2));
title(sprintf('Green Channel Mean: ROI#2: %.2f',mean(G(BW3==2))));
%
subplot(3,2,5)
imshow(B.*uint8(BW3==1));
title(sprintf('Blue Channel Mean: ROI#1: %.2f',mean(B(BW3==1))));
subplot(3,2,6)
imshow(B.*uint8(BW3==2));
title(sprintf('Blue Channel Mean: ROI#2: %.2f',mean(B(BW3==2))));
  2 个评论
Apra Gupta
Apra Gupta 2022-3-2
Thank u for the code Simon, but it is working well with this image only. I have number of images which i want to automate.
Can you plase tell the criteria of deciding the thresholds of R,G and B.
Apra Gupta
Apra Gupta 2022-3-8
Hello, I have applied the above code on attached image and didn't get result. Can someone please help.

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by