Gray Matter Area and Volume Calculations
조회 수: 4 (최근 30일)
이전 댓글 표시
Hello, I am working on gray matter area and volume calculation of brain MRI image. I have some doubts with my code below:
% Area Calculation
Pixel_Numbers = sum(J(:));
DistanceinUnit = 1.796875; %Based on pixel spacing (in mm?)
DistanceinPixel = sqrt(x^2+y^2);
DistancePerPixel = DistanceinUnit/DistanceinPixel;
Area = (Pixel_Numbers)*(DistancePerPixel^2); %Is it in mm^2 or mm^2/pixel?
% Volume Calculation (Is the formula correct?)
LengthinPixel = length(find(J(:)==1));
Length = LengthinPixel*DistanceinUnit;
Volume = Area*Length;
The information about pixel spacing is 1.796875\1.796875. I'd be glad if you can help me to figure out the answer. Here is the picture. Thank you.
댓글 수: 2
Image Analyst
2020년 4월 22일
What are the doubts? Does (the badly-named) J include that white frame around the image?
채택된 답변
Ryan Comeau
2020년 5월 6일
Hello, i think you're image appears to be binarized already. This means we can obtain the area well with the regionprops function. https://www.mathworks.com/help/images/ref/regionprops.html.
In terms of the volume, are you wanting to sum up the number of pixel in that area * intensity? In you case if the image is binary, the volume and area will be the same. volume=area*height but height is 1 because your image is binary.
The last thing you want now is pixels to mm? just determine the conversion for this, if a pixel is 1.796875x1.796875 we will have an area=(1.796875)^2*num_pixels.
If all the area is one block, it will be returned from regionprops, if not you'll need to sum it up. Here is my logic for this problem:
image=imread('J.jpg');
image=rescale(image,0,1); %helps for binarization
BW_im=imbinarize(image); %see documentation, it is versatile
hh=regionprops(BW_im,{'Centroid','Area',}); %centroid for locations.
total_area=0;
total_volume=0;
height=1;%your image is binary, if it's not this will change pixel by pixel.
%see the regionprops function to sum up pixel values as well.
for i=1:length(hh)
total_area=total_area+hh(i).Area;
total_volume=total_volume+(hh(i).Area*height)
end
area_in_mm=(1.796875.^2)*total_area;
Hope this helps, if not, drop a comment.
RC
댓글 수: 3
Ryan Comeau
2020년 5월 9일
편집: Ryan Comeau
2020년 5월 9일
Hello, in your code above, the bb is a struct and the line that has:
bbMatrix = vertcat(bb(:).BoundingBox)
Is taking a structure and transforming in into a matrix.
sidebar: in MATLAB, there are matrixes, cell matrices and structures.
This matrix is created because there is a hidden index which is not seen during the vertcat() operation. In this operation, both the structure array and the field of the structure array are indexed. In other words, the field is a vector. so for example, we can have bb(1).BoundinBox(3) or bb(3).BoundingBox(1). In this case, the height seems to be the third element of the bounding box, it's not the 3D height it's the 2D height. If you want the height of this bounding box, you don't actually need to remove it from the struct array, you could simply change the code as follows:
image=imread('J.jpg');
image=rescale(image,0,1);
BW_im=imbinarize(image);
hh=regionprops(BW_im,{'Centroid','Area','BoundingBox'});
total_area=0;
total_volume=0;
for i=1:length(hh)
total_area=total_area+(hh(i).BoundingBox(3)*hh(i).BoundingBox(4));%change is here
total_volume=total_volume+(hh(i).Area*1)
end
area_in_mm=(1.796875.^2)*total_area;
Please note, that the bounding box may return the height of the whole region on average(i don't know, you'll need to check the documentation) not the pixel by pixel height
A binary image is defined by have either 1 or 0. This is why the height is 1 for everything. If you had a greyscale brain scan, we could sum the height of each individual pixel to obtain a volume.
Hope this helps,
RC
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 3-D Volumetric Image Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!