How to calculate the summation pixel counts seperately.
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
mohd akmal masud
el 12 de Nov. de 2021
Editada: mohd akmal masud
el 18 de Oct. de 2022
Hi all, I have 146 slices images. That is dicom images. every pixel have their own counts (index number) like picture below. I used this below command to read it first.
%% Read main set data
clc
clear all
[spect map]=dicomread('I131256x256 10N1.dcm');
info = dicominfo('I131256x256 10N1.dcm');
%gp=info.SliceThickness;
spect=(squeeze(spect));%smooth3
aa=size(spect);aa=aa(3);
imshow3D(spect)
Then I used used command below to do some segmentation for the 4 sphere blob. The image binary as below.
%% NI KALAU VOLUME1 en amin prepapre 10:1
% BCKG 69 MAX 381 bckgratio=5.52
seedR1 = 110; seedC1 = 149; seedP2 = 88;
W1 = graydiffweight(spect, seedC1, seedR1, seedP2 , 'GrayDifferenceCutoff', 1000000);
thresh1 = 0.004478;
[BW1, D1] = imsegfmm(W1, seedC1, seedR1, seedP2, thresh1);
% figure, imshow3D(BW1)
T1 = regionprops('table', BW1,'Area','Centroid')
% NI KALAU VOLUME2 en amin prepapre 10:1
% BCKG 69 MAX 221 bckgratio=3.20
seedR2 = 134; seedC2 = 148; seedP2 = 88;
W2 = graydiffweight(spect, seedC2, seedR2, seedP2 , 'GrayDifferenceCutoff', 1000000);
thresh2 = 0.001437;
[BW2, D2] = imsegfmm(W2, seedC2, seedR2, seedP2, thresh2);
% figure, imshow3D(BW2)
T2 = regionprops('table', BW2,'Area','Centroid')
% NI KALAU VOLUME3 en amin prepapre 10:1
% BCKG 69 MAX 143 bckgratio=2.07
seedR3 = 146; seedC3 = 127; seedP3 = 88;
W3 = graydiffweight(spect, seedC3, seedR3, seedP3 , 'GrayDifferenceCutoff', 1000000);
thresh3 = 0.000326;
[BW3, D3] = imsegfmm(W3, seedC3, seedR3, seedP3, thresh3);
% figure, imshow3D(BW3)
T3 = regionprops('table', BW3,'Area','Centroid')
% NI KALAU VOLUME4 en amin prepapre 10:1
% BCKG 69 MAX 109 bckgratio=1.57
seedR4 = 134; seedC4 = 107; seedP4 = 88;
W4 = graydiffweight(spect, seedC4, seedR4, seedP4 , 'GrayDifferenceCutoff', 1000000);
thresh4 = 0.000092;
[BW4, D4] = imsegfmm(W4, seedC4, seedR4, seedP4, thresh4);
% figure, imshow3D(BW4)
T4 = regionprops('table', BW4,'Area','Centroid')
allBW = BW1 | BW2 | BW3 | BW4 ;
imshow3D(allBW);
My problem is how to get the total counts for each blob?
I try this one but it summation of all counts pixel for all blob
>> totalcountseachblob = sum(spect(allBW==1))
totalcountseachblob =
722358
Anyone can help me?
0 comentarios
Respuesta aceptada
yanqi liu
el 13 de Nov. de 2021
sir,may be use
save allBW.mat allBW
and upload this mat file, so we can do some code to analysis
5 comentarios
yanqi liu
el 13 de Nov. de 2021
clc; clear all; close all;
load('allBW')
% fd = fullfile(pwd, 'bws');
% if ~exist(fd, 'dir')
% mkdir(fd);
% end
% for i = 1 : size(allBW,3)
% imwrite(allBW(:,:,i), fullfile(fd, sprintf('%03d.png', i)));
% end
%figure; imshow(mat2gray(allBW(:,:,89)),[]);
% get the total counts for each blob
base_bw = allBW(:,:,88);
[L,num] = bwlabel(base_bw);
allBW1 = []; allBW2 = []; allBW3 = []; allBW4 = [];
for i = 1 : size(allBW,3)
bwi = allBW(:,:,i);
for j = 1 : num
% for each blob
mask = base_bw; mask(L~=j) = 0;
[r,c]=find(mask);
bwij = bwselect(bwi, c, r);
switch j
case 1
allBW1(:,:,i) = bwij;
case 2
allBW2(:,:,i) = bwij;
case 3
allBW3(:,:,i) = bwij;
case 4
allBW4(:,:,i) = bwij;
end
end
end
% use for each blob
load('spect')
totalcountseachblob1 = sum(spect(allBW1==1))
totalcountseachblob2 = sum(spect(allBW2==1))
totalcountseachblob3 = sum(spect(allBW3==1))
totalcountseachblob4 = sum(spect(allBW4==1))
totalcountseachblob = totalcountseachblob1+totalcountseachblob2+totalcountseachblob3+totalcountseachblob4
totalcountseachblob1 =
20760
totalcountseachblob2 =
55799
totalcountseachblob3 =
490376
totalcountseachblob4 =
155423
totalcountseachblob =
722358
>>
Más respuestas (1)
Image Analyst
el 13 de Nov. de 2021
@mohd akmal masud you have the image of all 4 blobs, allBW, so to get the area of each one you simply need to do
totalcountseachblob = nnz(allBW);
That is the total number of pixels in the binary image. If you want the "integrated gray values" from the original gray scale image, you can use that as a mask
pixelValues = spect(allBW);
igv = sum(pixelValues);
Also you have the "total counts for each blob" if you just run regionprops() on your allBW image:
allT = regionprops('table', allBW,'Area','Centroid') % The individual areas of each blob in a table.
allAreas = allT.Area; % The individual areas of each blob in a double vector.
1 comentario
Ver también
Categorías
Más información sobre 3-D Volumetric Image Processing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!