create 3D image from coordinates

조회 수: 4 (최근 30일)
France
France 2019년 12월 24일
댓글: Image Analyst 2019년 12월 28일
I have got a 3D nifti image (img) that is a breast MRI. For the same image, there are NX3 coordinates (x,y,z) in the file coordsV2f. I need to substitute these coordinates to new values that are in the file pred.txt, in order to highlight some pxels and show them marked in the original 3D image. It works and now I have my zeros image with some highlighted pixel. How can I visualize the marked pixels on the original one (img) and scroll down the slices?
many thanks !!!
img = niftiread([fCompletePath '_image']);
load (['19012302a_coordsV2f']);
x = RCS(:,1);
y = RCS(:,2);
z = RCS(:,3);
new_img = zeros(size(img));
k = 1;
for slice = 1 : length(z)
f = z(slice); %3rd dimension of RCS
newX= (x(k)); % get x
newY= (y(k)); % get y
new_img(newX,newY,f) = pred(k); %assign new value on a zeros image
k = k+1;
end
imshow(new_img(:,:,5),'DisplayRange',[])
save new_img %save in workspace
niftiwrite(new_img, [fName '_prediction.nii.gz']); %save as .nii

채택된 답변

Image Analyst
Image Analyst 2019년 12월 24일
You can extract each slice of the image in a for loop and call imshow(), then call hold on, and plot() to plot a red spot (or whatever) over the changed pixels. Then at the bottom of the loop call questdlg() to let the user see the image and spots before proceeding with the next image.
  댓글 수: 2
France
France 2019년 12월 28일
Thank you Image Analyst.
This is the code I wrote:
p = 1;
for n = 1: numel(img(:,:,p))
imshow(img(:,:,p), 'DisplayRange',[]);
hold on
plot(img(:,:,p), new_img(:,:,p), 'r');
p = p+1;
end
questdlg(img)
I am not sure you mean this. However, it does not work properly, since it put a red line as contour on the original img...
Thanks in advance for your help!
Image Analyst
Image Analyst 2019년 12월 28일
You certainly would not want to do that. Let's say img is a 3-D RGB image with 3 color channels. Let's say each channel was a megapixel. So you'd be calling imshow() a million times since n would go from 1 to a million. To plot a red dot over the changed pixels stored in x and y, you'd do
imshow(img);
hold on;
plot(x, y, 'r.', 'MarkerSize', 2);
hold off;
questdlg() asks the user a question. It takes a string as a user prompt, and some strings for response options the user can pick. Like
promptMessage = sprintf('Do you want to Continue processing,\nor Quit processing?');
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if contains(buttonText, 'Quit')
return;
end

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Red에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by