0

I am using a 3D raw image (size of PET image(float) is [84*71*103] with spacing size of 4.07*4.07*3 mm).

I want to:

  • Use the voxel coordinates [116,177,86] that correspond to center of the tumor (defined by me), and create a sphere that is concentric with the center of the tumor.
  • Change the diameter of the sphere to be a little bigger than the tumor itself.

So the sphere is going to serve as a mask which is overlaid with the image, and I can get the statistics of the values of the image within that spherical shape.

I hope I have made it clear enough. I would really appreciate your help. My code is not working correctly, and I don't know how to proceed.

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');
EBH
  • 10,350
  • 3
  • 34
  • 59
Hoda
  • 5
  • 5
  • I don't see where you have actually applied a filter to your image. Maybe you need to write something like: nonSphereVoxels = (rowsInImage - centerY).^2 + (columnsInImage - centerX).^2 + (pagesInImage - centerZ).^2 > radius.^2; and then set pet1_diff(nonSphereVoxels) = 0; – Airidas Korolkovas Aug 26 '16 at 11:42
  • Thanks alot for your reply. Yes I understand, but thats my problem. Im not sure how to apply the sphere as a logical mask on the PET image. I tried what you recommended but its still not creating the sphere on the image. – Hoda Aug 26 '16 at 14:45
  • Formatting the question and the code – EBH Aug 28 '16 at 21:04

1 Answers1

0

I have solved a simplified 2D version of your problem, I hope that this helps to answer your question. For starters, let's create an input

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

Next, we apply the cutoff:

[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])

Is this the kind of result you were aiming at?

  • Thanks alor Airidas. I tried your code and it works exactly like i need it to, just I need it in 3D. I tried doing exactly that with my image (3D), but it gives me a blank green window. – Hoda Aug 26 '16 at 16:04
  • @AiridasI just edited my code to match your suggestion, can you take a look please. Its giving me a blank (green) figure. – Hoda Aug 26 '16 at 16:14
  • try plotting around the center of the sphere: imagesc(pet1fem_pet2_diff(:,:,74)); – Airidas Korolkovas Aug 26 '16 at 16:16
  • Thanks alot . Yes I did that. The problem is that for some reason, the image does not seem to form a sphere (2D -circle)!! it more like lines!! I wish I could attach the figure but "stack overflow" wont allow me to do it. – Hoda Aug 26 '16 at 16:40
  • Is there a way I can display this resulting image in 3D? I really appreciate your time. This has been real helpful.Thank you :) – Hoda Aug 26 '16 at 16:41
  • This page gives you visualisation options: http://www.mathworks.com/help/matlab/visualize/techniques-for-visualizing-scalar-volume-data.html – Airidas Korolkovas Aug 26 '16 at 16:45