Applying a mask to 3D Data

조회 수: 30 (최근 30일)
Warren Boschen
Warren Boschen 2023년 3월 30일
편집: Walter Roberson 2023년 3월 31일
Hi everyone, I'm trying to generate a histogram of some data and I want to apply a 3D mask to the data. I have written as below, where fw is the data set that I'm trying to mask:
nbins = 20;
mask = find(mask);
selected_voxels = fw(mask); % ?
counts = histcounts(selected_voxels, nbins);
range = linspace(0, 1, nbins);
bar(range, counts)
I've chosen to use bar instead of MATLAB's histogram because I want to be able to place multiple bars beside one another and I've not found a way to do that using the basic histogram function. I used the find function since the values in my "mask" are not necessarily binary. However, a large number of voxels are being put in the highest bin.
The correct histogram should look as below, which I've plotted with Excel:
Does anyone have any suggestions on how to fix my histogram? Notably, the highest bin should not have a peak and the number of voxels included in the histogram should be significantly lower. I have included both fw and the mask in .mat format.
Thank you,
Warren

답변 (2개)

Anton Kogios
Anton Kogios 2023년 3월 30일
nbins = 20;
mask = mask==1;
selected_voxels = fw(mask); % ?
counts = histcounts(selected_voxels, nbins);
range = linspace(0, 1, nbins);
bar(range, counts)
  댓글 수: 1
Warren Boschen
Warren Boschen 2023년 3월 30일
The distribution looks better, but this only includes values of 1 in the mask, whereas I want to use any value that is non-zero. How would I change what you have to do that?

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2023년 3월 30일
Your fw is 128 by 128 by 72 which is 1179648 elements.
Your mask is 186456 x 1. That is less than 1/6th of the size of fw.
Are you sure the mask is the right size?? MATLAB will effectively pad out the mask with false to be the same size as the array, but it seems very odd that you would pull out that particular part of the original data.
  댓글 수: 2
Warren Boschen
Warren Boschen 2023년 3월 30일
Sorry about that! The imported mask should also be 128x128x72. I included the correct mask as a part of this comment. The mask is not the right size, which is why I asked this question in the first place. Since find(mask) produces a much smaller set than the original size, I can't reshape it to the correct 128x128x72. Is there a better way to get about this?
Walter Roberson
Walter Roberson 2023년 3월 31일
편집: Walter Roberson 2023년 3월 31일
A lot of your selected voxels are exactly 1. As long as your mask is correct, there should be a large number in the last bin in the plot.
nbins = 20;
load fw
load mask_correct
selected_voxels = fw(logical(mask));
nnz(selected_voxels == 1)
ans = 12626
counts = histcounts(selected_voxels, nbins);
range = linspace(0, 1, nbins);
bar(range, counts)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by