I need to find standard deviation from labeled matrix

1 次查看(过去 30 天)
My project need to find homogeneity from each cell from image so I decided to use SD for each cell
but I already try std(A) but it doesn't work I try meanintensity in regionprops but I don't know what to do next
do I have anyway to get SD from each labelmatrix
clear
clc
close all
IMG = imread('Cal-IR-MP-3.jpg');
blue = IMG(:,:,3);
th = graythresh(blue);
bw = imbinarize(blue,th);
bw = imclearborder(bw,8);
seD = strel('disk',3);
bw = imopen(bw,seD);
CC = bwconncomp(bw, 8);
L = labelmatrix(CC);
xx = [];
a = 1;
LL1 = L;
for i = 1:CC.NumObjects
LL = L;
if length(CC.PixelIdxList{i})<1000
LL(LL==i) = 0;
LL1(LL1==i) = 0;
else
LL(LL ~= i) = 0;
LL(LL == i)= 1;
xx(a,1) = i;
stats = regionprops(LL,blue,'MeanIntensity');
xx(a,2) = stats.MeanIntensity;
s = std2(i);
a = a+1;
end
end

采纳的回答

DGM
DGM 2021-3-27
编辑:DGM 2021-3-27
If what you're trying to do is get the standard deviation of the regions specified by the label matrix, try this.
clear variables; clc; close all
IMG = imread('sources/blacklight2.jpg'); % i used my own test image
blue = IMG(:,:,3);
th = graythresh(blue);
bw = imbinarize(blue,th);
bw = imclearborder(bw,8);
seD = strel('disk',3);
bw = imopen(bw,seD);
CC = bwconncomp(bw, 8);
L = labelmatrix(CC);
xx = [];
a = 1;
LL1 = L;
for i = 1:CC.NumObjects
% only evaluate groups above a certain size
if length(CC.PixelIdxList{i})<1000
% idk what you're doing with LL1
% i'll assume this is for something else
% LL was being rewritten and unused, so I removed it
LL1(LL1==i) = 0;
else
roidata=double(blue(L==i)); % extract the ROI
xx(a,:) = [i std(roidata(:))]; % write to output array
a = a+1;
end
end
xx
If LL1 isn't used for anything outside this scope, then it simplifies to
clear variables; clc; close all
IMG = imread('sources/blacklight2.jpg');
blue = IMG(:,:,3);
th = graythresh(blue);
bw = imbinarize(blue,th);
bw = imclearborder(bw,8);
seD = strel('disk',3);
bw = imopen(bw,seD);
CC = bwconncomp(bw, 8);
L = labelmatrix(CC);
xx = [];
a = 1;
for i = 1:CC.NumObjects
if length(CC.PixelIdxList{i})>=1000
roidata=double(blue(L==i));
xx(a,:) = [i std(roidata(:))];
a = a+1;
end
end
xx
idk if that helps
  2 个评论
Image Analyst
Image Analyst 2021-3-27
You can use bwareafilt() or bwareaopen() in advance of the labeling to avoid having to check blobs less than 1000 pixels inside the loop.
DGM
DGM 2021-3-27
编辑:DGM 2021-3-27
I was kind of assuming that maybe those small groups might be used for something else. Otherwise, yeah. That would clean things up a bit and potentially save some time as well.
IMG = imread('sources/blacklight2.jpg');
blue = IMG(:,:,3);
th = graythresh(blue);
bw = imbinarize(blue,th);
bw = imclearborder(bw,8);
seD = strel('disk',3);
bw = imopen(bw,seD); % idk that this is needed if using bwareaopen
bw = bwareaopen(bw,1000,8);
CC = bwconncomp(bw, 8);
L = labelmatrix(CC);
xx = zeros([CC.NumObjects 2]);
for i = 1:CC.NumObjects
roidata=double(blue(L==i));
xx(i,:) = [i std(roidata(:))];
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Segmentation and Analysis 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by