在3D图像上创建球体(作为蒙版)

时间:2016-08-25 16:28:49

标签: matlab mask d3dimage

我正在使用3D原始图像(PET图像(浮动)的尺寸为[84 * 71 * 103],间距尺寸为4.07 * 4.07 * 3 mm)。

我想:

  • 使用与肿瘤中心(由我定义)对应的体素坐标[116,177,86],并创建一个与肿瘤中心同心的球体。
  • 将球体的直径改为比肿瘤本身稍大。

因此,球体将作为与图像重叠的遮罩,我可以获得该球形内图像值的统计数据。

我希望我已经说清楚了。我将衷心感谢您的帮助。我的代码工作不正常,我不知道如何继续。

fid_1 = fopen('I:\PatientData\patient3\case1\DIR_CT1toCT2\New-     
crop\PET1FEM_PET2_DIFF.img','r','l');
pet1fem_pet2_diff = fread(fid_1,'float32');
pet1fem_pet2_diff = reshape(pet1fem_pet2_diff, [84 71 103]);
% interpolation is nearest neighbour, and 'crop' Makes output the same size as the input image
pet1fem_pet2_diff = imrotate(pet1fem_pet2_diff,90,'nearest','crop');

% create the image 
imageSizeX = 84;
imageSizeY = 71;
imageSizeZ = 103;
% columns are in the x direction and, rows are in the y direction
[columnsInImage rowsInImage pagesInImage] = meshgrid(1:imageSizeX, 1:imageSizeY,1:imageSizeZ);

% Next create the sphere in the image.
centerX = 29;
centerY = 26;
centerZ = 74;
radius = 5;

nonSphereVoxels = (rowsInImage - centerY).^2 ...
    + (columnsInImage - centerX).^2 + (pagesInImage - centerZ).^2 > radius.^2;
    pet1fem_pet2_diff(nonSphereVoxels) = 0;

figure(1);
imagesc(pet1fem_pet2_diff(:,:,30)); 
title('PET1FEM-PET2-DIFF');

1 个答案:

答案 0 :(得分:0)

我已经解决了问题的简化2D版本,我希望这有助于回答您的问题。首先,让我们创建一个输入

A = rand(128,128); % this is your pet1_diff data
% you can plot it like this:
clf reset
imagesc(A)
daspect([1 1 1])

接下来,我们应用截止值:

[x,y] = meshgrid(1:128,1:128);
r2 = ((x-40).^2 + (y-40).^2) > 10^2; % radius 10 cutoff from position (40,40)
A(r2) = 0; % delete pixels outside the cutoff radius

% plot the filtered data
clf reset
imagesc(A)
daspect([1 1 1])

这是你瞄准的那种结果吗?