MATLAB Answers

how to fix the figure so that can scroll slice by slice.

조회 수: 39(최근 30일)
mohd akmal masud
mohd akmal masud 22 Dec 2020
Hi all, i did my coding (as below) to view my image as fusion between SPECT and CT (my dicom image as attached)
But i have no idea, stuck and felt dead and. the figure is so weird.
I want to one figure can see the fusion between SPECT and CT and can scroll it slice by slice.
Can some one help me?
function sliderSpect
clear all
clc
warning off
scz = get(groot,'ScreenSize');
FigH = figure('position',[scz(3)/20 scz(4)/10 scz(3)/20*9 scz(4)/10*8],'Visible','on');
FigJ = figure('position',[scz(3)/20 scz(4)/10 scz(3)/20*9 scz(4)/10*8],'Visible','on');
% jFig = get(handle(gcf), 'JavaFrame');
% jFig.setMaximized(true);
FigQ = figure('position',[scz(3)/20*10 scz(4)/10 scz(3)/20*9 scz(4)/10*8],'Visible','on');
% movegui(FigH, 'center')
% 'position',[100 50 200 200], 'NextPlot', 'add');
% x = linspace(0, 4*pi, 400);
% y = sin(x);
% LineH = plot(x,y);
% Create push button
[spect map]=dicomread('I-131sphere10nisbah1');
infoS = dicominfo('I-131sphere10nisbah1');
SPgp=infoS.SliceThickness;
SPpicspc=infoS.PixelSpacing;
save infospect infoS
spect=(squeeze(spect));%smooth3
spect=spect(2:end-1,2:end-1,:);
% spect(spect<60)=60;
% spect(spect>200)=200;
MNLsp=double(size(spect));
% addlistener(SliderH, 'Value', 'PostSet', @callbackfn);
% % % btn3 = uicontrol('Style', 'pushbutton', 'String', 'start',...
% % % 'Position', [620 20 50 20],...
% % % 'Callback',@sv);
% cps1=spect([cursor_info.Position(2) cursor_info.Position(1) num])
spectmax=max(max(max(spect)));
spectmin=min(min(min(spect)));
spectrange=double(spectmax-spectmin);
d=14;%first slice
Folder='ct';%input('***Please enter the CT/MRI data folder name : ','s');
aa=dir(num2str(Folder));
aa=struct2cell(aa);
Slice=size(aa);
Slice=Slice(2);
f=1;ceil(Slice/300);% depands on PC capability 300 is optimum no of slice for this PC
c=round(Slice/f);%No of slices ...4yusoff
% clf
%RZ=zeros(round(400/f),round(500/f),round(c/f));
fprintf('\nReading images. Please wait...\n');
for a=4:1:Slice%Slice
Percent=floor(a/(Slice)*100)
as=[ Folder '\' char(aa(1,a))];
[X, map]=dicomread([as]);
% montage(X, map)
% pause(0.01)
infoC = dicominfo([as]);
Y = dicomread(infoC);
RZ(:,:,Slice-a+1)=Y;%(dpnblkg,kanankiri)
% imshow(Y, 'DisplayRange',[]);
% pause(0.2)
%saveas(gcf, [as '.png'])
%figure
%I = imread([as '.png']);
%imshow(I)
end
save info infoC
CTgp=infoC.SliceThickness;
CTpicspc=infoC.PixelSpacing;
FigH.Visible = 'on';
FigJ.Visible = 'on';
RZ=double(RZ);
[N M L]=size(RZ);
NCT=N*CTpicspc(2)% in mm
MCT=M*CTpicspc(1)
HCT=L*CTgp
NSP=MNLsp(2)*SPpicspc(2) % in mm
MSP=MNLsp(1)*SPpicspc(1)
HSP=MNLsp(3)*SPgp
sizediff=[NSP MSP HSP]-[NCT MCT HCT]
rats=[CTpicspc(2) CTpicspc(1) CTgp]./[SPpicspc(2) SPpicspc(1) SPgp]
[x,y,z]=meshgrid(sizediff(2)/2/SPpicspc(1)+rats(2)/2:rats(2):MNLsp(1)-sizediff(2)/2/SPpicspc(1),...
sizediff(1)/2/SPpicspc(2)+rats(1)/2:rats(1):MNLsp(2)-sizediff(1)/2/SPpicspc(2),...
sizediff(3)/2/SPgp+rats(3)/2:rats(1):MNLsp(3)-sizediff(3)/2/SPgp);
spect=double(spect);
spect=interp3(spect,x,y,z);
aaa=size(spect);
% rats=[NCT MCT HCT]./[NSP MSP HSP];
% [x,y,z]=meshgrid(rats(1):rats(1):M,rats(2):rats(2):N,rats(3):rats(3):L);
% RZ=interp3(RZ,x,y,z);
figure(FigH)
% Create pop-up menu
TextH = uicontrol('style','text',...
'position',[200 50 150 20],'String','SPECT-Slices');
SliderH = uicontrol('style','slider','position',[100 20 400 20],...
'min', 0, 'max', aaa(3),'SliderStep', [1/aaa(3), 10/aaa(3)],'Callback', @callbackfn);
figure(FigJ)
% Create pop-up menu
TextJ = uicontrol('style','text',...
'position',[200 50 150 20],'String','Front-Slices');
SliderJ = uicontrol('style','slider','position',[100 20 400 20],...
'min', 0, 'max', aaa(1),'SliderStep', [1/aaa(1), 10/aaa(1)],'Callback', @callbackfnJ);
figure(FigQ)
TextQ = uicontrol('style','text',...
'position',[200 50 150 20],'String','Count Value');
SliderQ = uicontrol('style','slider','position',[100 20 400 20],...
'min', spectmin, 'max', spectmax, 'value', 150,'SliderStep',[1/spectrange, 100/spectrange],'Callback', @sv);%,'SliderStep', [1/spectrange, 10/spectrange]
figure(FigH)
function callbackfn(source,~)
num = source.Value
% slicemax=max(max(spect(:,:,ceil(num))));
slicemax=max(max(RZ(:,:,ceil(num))))
slicemin=min(min(RZ(:,:,ceil(num))))
if slicemax>0
% montage(RZ(:,:,ceil(num)),'DisplayRange', [slicemin slicemax]);
imshow(RZ(:,:,ceil(num)),'DisplayRange', [16000 17200]);
TextH.String = ['SPECT-Slices no. : ' num2str(ceil(num))];
figure(FigQ)
subplot(1,2,1)
g = hgtransform('Matrix',makehgtform('translate',[0 0 num]));
zoom off
srz=size(spect);
axis([0 srz(2) 0 srz(1) 0 srz(3)]);
gg=image(g,spect(:,:,ceil(num)));
subplot(1,2,2)
fusedall=imfuse(RZ(:,:,ceil(num)),spect(:,:,ceil(num)),'ColorChannels',[1 2 0]);
imshow(fusedall);
pause(5)
delete(gg)
zoom on
end
end
figure(FigJ)
function callbackfnJ(source,~)
num = source.Value
slicemax=max(max(spect(ceil(num),:,:)));
TextJ.String = ['Front-Slice no. : ' num2str(ceil(num))];
if slicemax>0
mon=montage(permute(spect(ceil(num),:,:),[3 2 1]),'DisplayRange', [0 slicemax]);
figure(FigQ)
% subplot(1,2,1)
% g = hgtransform('Matrix',makehgtform('translate',[num 0 0]));
% zoom off
% srz=size(spect);
% axis([0 srz(2) 0 srz(1) 0 srz(3)]);
%
% gg=image(g,mon);
subplot(1,2,2)
fusedall=imfuse(permute(RZ(ceil(num),:,:),[3 2 1]),permute(spect(ceil(num),:,:),[3 2 1]),'ColorChannels',[1 2 0]);
imshow(fusedall);
pause(5)
% delete(gg)
zoom on
end
end
figure(FigQ)
subplot(1,2,1)
camlight('headlight')
% whitebg('black')
colordef black
axis off% cps1=150;%input('Pixel value of high CPS : ');
% cps2=input('Pixel value of low CPS : ');
e=10000;%isovalue, air at 0 (Faceskin800, air1250)
fprintf('\nFull Reconstruction. Please wait...\n');
% for e=min(min(min(RZ))):1000:max(max(max(RZ)))
% plot3(0.5,0.5,0.5);
% hold;
q = patch(isosurface(RZ,e));
axis equal
set(q,'FaceColor','w','EdgeColor','none');
alpha(q,0.2)
material shiny
hold
qq = patch(isosurface(RZ,20000));
axis equal
set(qq,'FaceColor','w','EdgeColor','none');
alpha(qq,1)
material shiny
% title([num2str(e)]);
view([-35 16])
srz=size(RZ);
axis([0 srz(2) 0 srz(1) 0 srz(3)]);
% camlight('left')
% pause(0.01)
% grid
% end
figure(FigQ)
subplot(1,2,1)
function sv(source,q,qq)
p=q;
cps1 = source.Value
TextQ.String = ['Count Value : ' num2str(ceil(cps1))];
delete(gca)
q = patch(isosurface(RZ,e));
set(q,'FaceColor','w','EdgeColor','none');
alpha(q,0.2)
hold
clf
qq = patch(isosurface(RZ,16700));
set(qq,'FaceColor','w','EdgeColor','none');
material shiny
axis equal
camlight('headlight')
alpha(qq,0.9)
hold
% title([num2str(e)]);
% p = patch(isosurface(spect,cps1));
p = patch(isosurface(spect,395));
set(p,'FaceColor','m','EdgeColor','none');
material shiny
axis equal
camlight('headlight')
% whitebg('black')
colordef black
axis off% cps1=150;%input('Pixel value of high CPS : ');
view([-35 16])
srz=size(RZ);
axis([0 srz(2) 0 srz(1) 0 srz(3)]);
alpha(p,1)
hold
end
save RZnSPECT RZ spect
load RZnSPECT
% figure
% for c=1:size(RZ,3)
% fusedall=imfuse(RZ(:,:,c),spect(:,:,c));
% imshow(fusedall);
% pause
% end
end

답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by