Skip to content

Commit

Permalink
Merge branch 'master' into coc
Browse files Browse the repository at this point in the history
  • Loading branch information
agahkarakuzu committed Apr 3, 2019
2 parents 2400425 + 520a9bb commit 3886ab2
Show file tree
Hide file tree
Showing 16 changed files with 189 additions and 81 deletions.
19 changes: 12 additions & 7 deletions External/imtool3D_td/imtool3D.m
Expand Up @@ -393,8 +393,8 @@

%Create view restore button
tool.handles.Tools.ViewRestore = uicontrol(tool.handles.Panels.Tools,'Style','pushbutton','String','','Position',[lp buff w w],'TooltipString',sprintf('Reset Pan and Zoom\n(Right Click (Ctrl+Click) to Pan and Middle (Shift+Click) Click to zoom)'));
[iptdir, MATLABdir] = ipticondir;
icon_save = makeToolbarIconFromPNG([iptdir '/overview_zoom_in.png']);
MATLABdir = fullfile(toolboxdir('matlab'), 'icons');
icon_save = makeToolbarIconFromPNG('overview_zoom_in.png');
set(tool.handles.Tools.ViewRestore,'CData',icon_save);
fun=@(hobject,evnt) resetViewCallback(hobject,evnt,tool);
set(tool.handles.Tools.ViewRestore,'Callback',fun)
Expand Down Expand Up @@ -569,7 +569,7 @@

% mask statistics
tool.handles.Tools.maskStats = uicontrol(tool.handles.Panels.ROItools,'Style','togglebutton','Position',[buff pos(4)-(islct+2)*w w w], 'Value', 1, 'TooltipString', 'Statistics');
icon_hist = makeToolbarIconFromPNG([MATLABdir '/plottype-histogram.png']);
icon_hist = makeToolbarIconFromPNG('plottype-histogram.png');
icon_hist = min(1,max(0,imresize(icon_hist,[16 16])));
set(tool.handles.Tools.maskStats ,'Cdata',icon_hist)
set(tool.handles.Tools.maskStats ,'Callback',@(hObject,evnt) StatsCallback(hObject,evnt,tool))
Expand Down Expand Up @@ -613,7 +613,12 @@

% set Image
setImage(tool, varargin{:})


% disable ROI tools if no image processing toolbox
result = license('test','image processing toolbox');
if result==0
warning('Image processing toolbox is missing... ROI tools will not work')
end
end

function setPosition(tool,position)
Expand Down Expand Up @@ -834,11 +839,11 @@ function setImage(tool, varargin)
end
range = tool.Climits{1};

tool.Nvol = 1;

tool.I=I;

tool.setMask(mask);

tool.Nvol = 1;

%Update the histogram
if isfield(tool.handles,'HistAxes')
Expand Down Expand Up @@ -1814,7 +1819,7 @@ function ActiveCountourCallback(hObject,evnt,tool)
end

function measureImageCallback(hObject,evnt,tool,type)

removeBrushObject(tool)
switch type
case 'ellipse'
h = getHandles(tool);
Expand Down
20 changes: 12 additions & 8 deletions External/imtool3D_td/imtool3DROI_ellipse.m
Expand Up @@ -297,15 +297,19 @@ function ButtonDownFunction(hObject,evnt,ROI,n)
%get the parent figure handle
fig = ROI.figureHandle;

%get the current button motion and button up functions of the figure
WBMF_old = get(fig,'WindowButtonMotionFcn');
WBUF_old = get(fig,'WindowButtonUpFcn');

%set the new window button motion function and button up function of the figure
fun = @(src,evnt) ButtonMotionFunction(src,evnt,ROI,n);
fun2=@(src,evnt) ButtonUpFunction(src,evnt,ROI,WBMF_old,WBUF_old);
set(fig,'WindowButtonMotionFcn',fun,'WindowButtonUpFcn',fun2);
%get the type of click
click = get(fig,'SelectionType');

if strcmp(click,'normal')
%get the current button motion and button up functions of the figure
WBMF_old = get(fig,'WindowButtonMotionFcn');
WBUF_old = get(fig,'WindowButtonUpFcn');

%set the new window button motion function and button up function of the figure
fun = @(src,evnt) ButtonMotionFunction(src,evnt,ROI,n);
fun2=@(src,evnt) ButtonUpFunction(src,evnt,ROI,WBMF_old,WBUF_old);
set(fig,'WindowButtonMotionFcn',fun,'WindowButtonUpFcn',fun2);
end
end

function ButtonMotionFunction(src,evnt,ROI,n)
Expand Down
19 changes: 10 additions & 9 deletions External/imtool3D_td/imtool3DROI_line.m
Expand Up @@ -211,15 +211,16 @@ function ButtonDownFunction(hObject,evnt,ROI,n)
%get the type of click
click = get(ROI.figureHandle,'SelectionType');

%get the point that was clicked
dist = sqrt((position_old(:,1)-op(1)).^2 + (position_old(:,2)-op(2)).^2 );
[~, ind] = min(dist);

%set the new window button motion function and button up function of the figure
fun = @(src,evnt) ButtonMotionFunction(src,evnt,ROI,n,op,position_old,ind);
fun2=@(src,evnt) ButtonUpFunction(src,evnt,ROI,WBMF_old,WBUF_old);
set(fig,'WindowButtonMotionFcn',fun,'WindowButtonUpFcn',fun2);

if strcmp(click,'normal')
%get the point that was clicked
dist = sqrt((position_old(:,1)-op(1)).^2 + (position_old(:,2)-op(2)).^2 );
[~, ind] = min(dist);

%set the new window button motion function and button up function of the figure
fun = @(src,evnt) ButtonMotionFunction(src,evnt,ROI,n,op,position_old,ind);
fun2=@(src,evnt) ButtonUpFunction(src,evnt,ROI,WBMF_old,WBUF_old);
set(fig,'WindowButtonMotionFcn',fun,'WindowButtonUpFcn',fun2);
end
end

function ButtonMotionFunction(src,evnt,ROI,n,op,position_old,ind)
Expand Down
3 changes: 3 additions & 0 deletions External/imtool3D_td/imtool3DROI_poly.m
Expand Up @@ -317,6 +317,9 @@ function ButtonDownFunction(hObject,evnt,ROI,n)

%get the type of click
click = get(ROI.figureHandle,'SelectionType');
if strcmp(click,'alt') % right click to get menu
return
end

%set the default ind
ind=0;
Expand Down
20 changes: 12 additions & 8 deletions External/imtool3D_td/imtool3DROI_rect.m
Expand Up @@ -277,15 +277,19 @@ function ButtonDownFunction(hObject,evnt,ROI,n)
%get the parent figure handle
fig = ROI.figureHandle;

%get the current button motion and button up functions of the figure
WBMF_old = get(fig,'WindowButtonMotionFcn');
WBUF_old = get(fig,'WindowButtonUpFcn');

%set the new window button motion function and button up function of the figure
fun = @(src,evnt) ButtonMotionFunction(src,evnt,ROI,n);
fun2=@(src,evnt) ButtonUpFunction(src,evnt,ROI,WBMF_old,WBUF_old);
set(fig,'WindowButtonMotionFcn',fun,'WindowButtonUpFcn',fun2);
%get the type of click
click = get(fig,'SelectionType');

if strcmp(click,'normal')
%get the current button motion and button up functions of the figure
WBMF_old = get(fig,'WindowButtonMotionFcn');
WBUF_old = get(fig,'WindowButtonUpFcn');

%set the new window button motion function and button up function of the figure
fun = @(src,evnt) ButtonMotionFunction(src,evnt,ROI,n);
fun2=@(src,evnt) ButtonUpFunction(src,evnt,ROI,WBMF_old,WBUF_old);
set(fig,'WindowButtonMotionFcn',fun,'WindowButtonUpFcn',fun2);
end
end

function ButtonMotionFunction(src,evnt,ROI,n)
Expand Down
4 changes: 2 additions & 2 deletions External/imtool3D_td/imtool3D_3planes.m
Expand Up @@ -59,8 +59,8 @@
controls3 = cat(1,controls3,tool(2).getHandles.Tools.maskSelected',tool(2).getHandles.Tools.maskLock);

for ic = 1:length(controls1)
if ~isempty(controls1(ic).Callback) && contains(func2str(controls1(ic).Callback),'saveImage'), continue; end % save Mask only once!
if ~isempty(controls1(ic).Callback) && contains(func2str(controls1(ic).Callback),'displayHelp'), continue; end % Display Help only once!
if ~isempty(controls1(ic).Callback) && ~isempty(strfind(func2str(controls1(ic).Callback),'saveImage')), continue; end % save Mask only once!
if ~isempty(controls1(ic).Callback) && ~isempty(strfind(func2str(controls1(ic).Callback),'displayHelp')), continue; end % Display Help only once!

CB = get(controls1(ic),'Callback');
CB2 = get(controls2(ic),'Callback');
Expand Down
@@ -1,4 +1,4 @@
function imtool3D_3planes_crop(tool)
function RECTS = imtool3D_3planes_rect(tool)
% imtool3D_3planes_crop(tool) adds a synchronized rectangle to the imtool
% object created by imtool3D_3planes
%
Expand All @@ -24,5 +24,7 @@ function imtool3D_3planes_crop(tool)

tool(1).getHandles.fig

RECTS = cat(1,RECT1,RECT2,RECT3);



2 changes: 1 addition & 1 deletion External/imtool3D_td/imtool3D_nii_3planes.m
Expand Up @@ -40,7 +40,7 @@
Pos = get(tool(1).getHandles.Tools.Save,'Position');
Pos(1) = Pos(1) + Pos(3)+5;
Loadbut = uicontrol(tool(1).getHandles.Panels.Tools,'Style','pushbutton','String','','Position',Pos);
[iptdir, MATLABdir] = ipticondir;
MATLABdir = fullfile(toolboxdir('matlab'), 'icons');
icon_load = makeToolbarIconFromPNG([MATLABdir '/file_open.png']);
set(Loadbut,'CData',icon_load);
fun=@(hObject,evnt) loadImage(hObject,tool,hdr,path);
Expand Down
61 changes: 61 additions & 0 deletions External/imtool3D_td/imtool3D_nii_crop.m
@@ -0,0 +1,61 @@
function imtool3D_nii_crop(filename)
nii = nii_tool('load',filename);
tool = imtool3D_3planes(nii.img);
for ii=1:3
tool(ii).setAspectRatio(nii.hdr.pixdim(2:4));
end
RECTS = imtool3D_3planes_rect(tool);

waitfor(tool(ii).getHandles.fig);

pos = RECTS(1).getPosition();
cut_from_L = floor(pos(2)-pos(4)/2);
cut_from_R = floor(pos(2)+pos(4)/2);
cut_from_P = floor(pos(1)-pos(3)/2);
cut_from_A = floor(pos(1)+pos(3)/2);
pos = RECTS(2).getPosition();
cut_from_I = floor(pos(1)-pos(3)/2);
cut_from_S = floor(pos(1)+pos(3)/2);

nii.img = nii.img( cut_from_L+1 : cut_from_R, ...
cut_from_P+1 : cut_from_A, ...
cut_from_I+1 : cut_from_S, ...
:,:,:,:,:);


b = nii.hdr.quatern_b;
c = nii.hdr.quatern_c;
d = nii.hdr.quatern_d;

if 1.0-(b*b+c*c+d*d) < 0
if abs(1.0-(b*b+c*c+d*d)) < 1e-5
a = 0;
else
error('Incorrect quaternion values in this NIFTI data.');
end
else
a = sqrt(1.0-(b*b+c*c+d*d));
end

R = [a*a+b*b-c*c-d*d 2*b*c-2*a*d 2*b*d+2*a*c
2*b*c+2*a*d a*a+c*c-b*b-d*d 2*c*d-2*a*b
2*b*d-2*a*c 2*c*d+2*a*b a*a+d*d-c*c-b*b];

qmod = R*[cut_from_L*nii.hdr.pixdim(2);cut_from_P*nii.hdr.pixdim(3);cut_from_I*nii.hdr.pixdim(4)*nii.hdr.pixdim(1)];
nii.hdr.qoffset_x = nii.hdr.qoffset_x + qmod(1);
nii.hdr.qoffset_y = nii.hdr.qoffset_y + qmod(2);
nii.hdr.qoffset_z = nii.hdr.qoffset_z + qmod(3);

nii.hdr.srow_x(4) = nii.hdr.srow_x(4) + ...
nii.hdr.srow_x(1)*cut_from_L + ...
nii.hdr.srow_x(2)*cut_from_P + ...
nii.hdr.srow_x(3)*cut_from_I;
nii.hdr.srow_y(4) = nii.hdr.srow_y(4) + ...
nii.hdr.srow_y(1)*cut_from_L + ...
nii.hdr.srow_y(2)*cut_from_P + ...
nii.hdr.srow_y(3)*cut_from_I;
nii.hdr.srow_z(4) = nii.hdr.srow_z(4) + ...
nii.hdr.srow_z(1)*cut_from_L + ...
nii.hdr.srow_z(2)*cut_from_P + ...
nii.hdr.srow_z(3)*cut_from_I;
nii_tool('save',nii,[strrep(strrep(filename,'.nii.gz',''),'.nii','') '_crop.nii'])
63 changes: 51 additions & 12 deletions External/imtool3D_td/src/StatsGUI.m
Expand Up @@ -25,19 +25,58 @@
datiii = nanmean(I(:,:,:,:,length(fields)+1-iii),4);
end
datiii = datiii(Mask);
Stats{iii,1} = mean(datiii);
Stats{iii,2} = median(datiii);
Stats{iii,3} = std(datiii);
Stats{iii,4} = min(datiii);
Stats{iii,5} = max(datiii);
[Stats{iii,6}, Stats{iii,7}] = range_outlier(datiii,0);
Stats{iii,8} = Stats{iii,7} - Stats{iii,6};
Stats{iii,1} = sum(Mask(:));
Stats{iii,2} = mean(datiii);
Stats{iii,3} = median(datiii);
Stats{iii,4} = std(datiii);
Stats{iii,5} = min(datiii);
Stats{iii,6} = max(datiii);
[Stats{iii,7}, Stats{iii,8}] = range_outlier(datiii,0);
Stats{iii,9} = Stats{iii,7} - Stats{iii,6};
end

uitable(f,'Units','normalized','Position',[0,yprev - 1/length(values),1,1/length(values)],'Data',Stats,...
'ColumnName',{'mean', 'median', 'std','min','max','1st quartile', '3rd quartile', 'Interquartile Range (IQR)'},...
'ColumnFormat',{'numeric', 'numeric', 'numeric','numeric','numeric','numeric','numeric','numeric'},...
'ColumnEditable',[false false false false false false false false false],...
'RowName',fields','BackgroundColor',Color(Selected+1,:).*[.4 .4 .4]+1-[.4 .4 .4]);
T = uitable(f,'Units','normalized','Position',[0,yprev - 1/length(values),1,1/length(values)],'Data',Stats,...
'ColumnName',{'Volume (pixels)','mean', 'median', 'std','min','max','1st quartile', '3rd quartile', 'Interquartile Range (IQR)'},...
'ColumnFormat',{'numeric','numeric', 'numeric', 'numeric','numeric','numeric','numeric','numeric','numeric'},...
'ColumnEditable',[false false false false false false false false false false],...
'RowName',fields(:),'BackgroundColor',Color(Selected+1,:).*[.4 .4 .4]+1-[.4 .4 .4]);
yprev = yprev - 1/length(values);

Stats_all{Selected+1} = cat(2,[{'Volume'} fields(:)']',cat(1,{'Volume (pixels)','mean', 'median', 'std','min','max','1st quartile', '3rd quartile', 'Interquartile Range (IQR)'},Stats));
end

uimenu(f,'Label','export statistics','Callback',@(src,evnt) exportStats(Stats_all,values))

function exportStats(Stats_all,values)
[file,path,ext] = uiputfile({'.txt','(.txt) Tabulated text file';'*.xls','(.xls) Excel file'});

if isnumeric(file)
return;
end

switch ext
case 1
fid = fopen(fullfile(path,file),'w');
for ival=values
fprintf(fid,'#Label: %d\n',ival);
Header = Stats_all{ival+1}(1,:);
fprintf(fid,'%s\t',Header{:});
fprintf(fid,'\n');
for iline = 2:size(Stats_all{ival+1},1)
Valiline = Stats_all{ival+1}(iline,:);
for icol = 1:size(Stats_all{ival+1},2)
if isnumeric(Valiline{icol})
fprintf(fid,'%g\t',Valiline{icol});
else
fprintf(fid,'%s\t',Valiline{icol});
end
end
fprintf(fid,'\n');
end
end
fclose(fid);
case 2
for ival=values
xlswrite(fullfile(path,file),Stats_all{ival+1},['Label' num2str(ival)])
end
end
Binary file added External/imtool3D_td/src/overview_zoom_in.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added External/imtool3D_td/src/plottype-histogram.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions External/imtool3D_td/src/setviewplane.m
@@ -0,0 +1,14 @@
function dat = setviewplane(dat,viewplane)
if nargin<2 || isempty(viewplane), viewplane = 'axial'; end
if ~iscell(dat), dat = {dat}; numericdat = true;
else
numericdat = false;
end
switch viewplane
case 'sagittal'
dat = cellfun(@(x) permute(x,[2 3 1 4 5]),dat,'UniformOutput',false);
case 'coronal'
dat = cellfun(@(x) permute(x,[1 3 2 4 5]),dat,'UniformOutput',false);
end

if numericdat, dat = dat{1}; end
33 changes: 4 additions & 29 deletions qMRLab.m
Expand Up @@ -501,36 +501,11 @@ function Stats_Callback(hObject, eventdata, handles)

I = handles.tool.getImage(1);
Iraw = handles.CurrentData;
I = I(~strcmp(Iraw.fields,'Mask'));
Iraw.fields = setdiff(Iraw.fields,'Mask')';
fields = setdiff(Iraw.fields,'Mask')';
Maskall = handles.tool.getMask(1);
values = unique(Maskall(Maskall>0))';
yprev = 1;
if isempty(values), values = 0; end
f=figure('Position', [100 100 700 400], 'Name', 'Statistics');
for Selected = values
Mask = Maskall==Selected;
Stats = cell(length(Iraw.fields),7);
for iii=1:length(Iraw.fields)
datiii = I{length(Iraw.fields)+1-iii};
datiii = nanmean(datiii,4); % average 4D data along time
datiii = datiii(Mask);
Stats{iii,1} = mean(datiii);
Stats{iii,2} = median(datiii);
Stats{iii,3} = std(datiii);
Stats{iii,4} = min(datiii);
Stats{iii,5} = max(datiii);
[Stats{iii,6}, Stats{iii,7}] = range_outlier(datiii,0);
Stats{iii,8} = Stats{iii,7} - Stats{iii,6};
end
Color = handles.tool.getMaskColor;
uitable(f,'Units','normalized','Position',[0,yprev - 1/length(values),1,1/length(values)],'Data',Stats,...
'ColumnName',{'mean', 'median', 'std','min','max','1st quartile', '3rd quartile', 'Interquartile Range (IQR)'},...
'ColumnFormat',{'numeric', 'numeric', 'numeric','numeric','numeric','numeric','numeric','numeric'},...
'ColumnEditable',[false false false false false false false false false],...
'RowName',Iraw.fields','BackgroundColor',Color(Selected+1,:).*[.4 .4 .4]+1-[.4 .4 .4])
yprev = yprev - 1/length(values);
end
Color = handles.tool.getMaskColor;
StatsGUI(I,Maskall, fields, Color);


% HISTOGRAM FIG
function Histogram_Callback(hObject, eventdata, handles)
Expand Down
5 changes: 1 addition & 4 deletions src/Common/tools/GUIfun/DrawPlot.m
Expand Up @@ -4,11 +4,7 @@ function DrawPlot(handles,CurrentName)
else
set(handles.SourcePop, 'Value', find(strcmp(handles.CurrentData.fields,CurrentName)));
end
set(handles.ViewPop, 'Value', 1);
handles.tool.setviewplane(3);
set(handles.ViewPop, 'UserData', 1);

UpdatePopUp(handles);

Data = handles.CurrentData;
if isfield(Data,'Mask'), Mask = Data.Mask; Data.fields(strcmp(Data.fields,'Mask'))=[]; else Mask = []; end
Expand All @@ -20,6 +16,7 @@ function DrawPlot(handles,CurrentName)
Current{1} = Mask;
end
handles.tool.setImage(Current,[],[],[],[],Mask);
UpdatePopUp(handles);

% Set Volume Number
if exist('CurrentName','var')
Expand Down

0 comments on commit 3886ab2

Please sign in to comment.