Skip to content

Commit

Permalink
Significant rewrite of superSeggerViewerGui and underlying code to wo…
Browse files Browse the repository at this point in the history
…rk with multiple channels
  • Loading branch information
Paul Wiggins committed Jun 15, 2018
1 parent 4fc7ad3 commit a4f36ed
Show file tree
Hide file tree
Showing 6 changed files with 351 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Internal/intGetChannelNum.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function nnc = intGetChannelNum( data )
%% comp number of fluor channels

nc = numel(find(~cellfun('isempty',strfind(fieldnames(data),'fluor'))));
nnc = 0;

for jj = 1:nc

fluorName = ['fluor',num2str(jj)];

if isfield( data, fluorName )
nnc = nnc + 1;
end

end

end
6 changes: 6 additions & 0 deletions Internal/intMakeMinMax.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function minmax = intMakeMinMax( im )
minner = medfilt2( im, [2,2], 'symmetric' );
maxxer = max( minner(:));
minner = min( minner(:));
minmax = [minner,maxxer];
end
6 changes: 6 additions & 0 deletions Internal/intRange.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function ranger = intRange( im, CDFr )
% put max and min in range

ranger = [min( im ),max( im )];

end
109 changes: 109 additions & 0 deletions viz/doDrawCellOutlinePAW.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
function doDrawCellOutlinePAW( data, channel, ids1, ids2)
% Description :
%
% Opens fig with outlines of cells drawn. The script currently allows
% you to input two sets of cell IDs to be colored in blue (ids1) and red
% (ids2). Currently any cells with IDs not listed in ids1 or ids2 will be
% outlined in yellow. This is all customizable. If you wish to
% change the colors, replace 'b' etc with the color of your choice. If you
% do not want cells whose IDs are missing from the ID lists to be outlined,
% remove code in 'else' block. If you wish to send in additional id lists,
% add ids3, etc to the line above, and ammend the if/else block.
%
% List of inputs:
%
% data: A loaded err.mat file for the image you want outlines drawn on
% channel: The channel to draw outline on (1-phase, 2-fluor1)
% ids1: IDs of cells you want outlined in one color (default: blue)
% ids2: IDs of cells you want outlined in a second color (default: red)
%
%
% Copyright (C) 2016 Wiggins Lab
% Written by Silas Boye Nissen, Connor Brennan, Stella Stylianidou.
% University of Washington, 2016. Modified in 2018 by S Mangiameli and
% P. Wiggins.
% This file is part of SuperSegger.
%
% SuperSegger is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% SuperSegger is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with SuperSegger. If not, see <http://www.gnu.org/licenses/>.

% Fill unset inputs
if ~exist('ids1','var') || isempty( ids1 )
ids1 = [];
end

if ~exist('ids2','var') || isempty( ids2 )
ids2 = [];
end







% Draw outlines

rl = data.regs.regs_label;
ids = data.regs.ID;
nc = max( rl(:) );

props = regionprops( rl, 'PixelList' );

% Sets color depending on cell ID
for ii = 1:nc

id = ids(ii);

if ismember(id,ids1)
cc = 'b';
elseif ismember(id, ids2)
cc = 'r';
else
cc = 'y';
end

% Mask for current region
tmp = rl;
tmp(tmp ~= ii) = 0;

% Increase size of mask by 1 px and find boundary
se = strel('disk',1);
tmp2 = logical(imdilate(tmp,se));
[y,x] = find(tmp2 == 1);
k = boundary(x,y,1);


hold on;
skip = 1;
kk = k([1:skip:end]);
kk = kk([end-3:end,1:end,1:4]);

n = 1:numel(kk);
nn = 5:1:(numel(kk)-1);

% Interprets from pixel outline to smooth drawn outline
% xx = interp1( n, x(kk), nn,'spline' );
% yy = interp1( n, y(kk), nn,'spline' );

p = 0.1; %smaller value of p gives more smoothing
xx = fnval(csaps( n, x(kk),p), nn);
yy = fnval(csaps( n, y(kk),p), nn);


% Plots outline on phase image
plot( xx, yy, 'LineStyle','-','Color',cc,'LineWidth', .5 );

end

end
119 changes: 119 additions & 0 deletions viz/doDrawCellOutlineSMM.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
function doDrawCellOutlineSMM( data, channel, ids1, ids2)
% Description :
%
% Opens fig with outlines of cells drawn. The script currently allows
% you to input two sets of cell IDs to be colored in blue (ids1) and red
% (ids2). Currently any cells with IDs not listed in ids1 or ids2 will be
% outlined in yellow. This is all customizable. If you wish to
% change the colors, replace 'b' etc with the color of your choice. If you
% do not want cells whose IDs are missing from the ID lists to be outlined,
% remove code in 'else' block. If you wish to send in additional id lists,
% add ids3, etc to the line above, and ammend the if/else block.
%
% List of inputs:
%
% data: A loaded err.mat file for the image you want outlines drawn on
% channel: The channel to draw outline on (1-phase, 2-fluor1)
% ids1: IDs of cells you want outlined in one color (default: blue)
% ids2: IDs of cells you want outlined in a second color (default: red)
%
%
% Copyright (C) 2016 Wiggins Lab
% Written by Silas Boye Nissen, Connor Brennan, Stella Stylianidou.
% University of Washington, 2016. Modified in 2018 by S Mangiameli and
% P. Wiggins.
% This file is part of SuperSegger.
%
% SuperSegger is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% SuperSegger is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with SuperSegger. If not, see <http://www.gnu.org/licenses/>.

% Fill unset inputs
if ~exist('ids1','var') || isempty( ids1 )
ids1 = [];
end

if ~exist('ids2','var') || isempty( ids2 )
ids2 = [];
end

if ~exist('channel','var') || isempty( channel )
channel = 1;
end

clf;

% To draw outlines on the fluorescence image, replace phase with fluor
if channel == 1
im = cat(3, ag(data.phase), ag(data.phase), ag(data.phase));
elseif channel == 2
im = cat(3, ag(data.fluor1)*0, ag(data.fluor1), ag(data.fluor1)*0);
elseif channel ==3
im = cat(3, ag(data.fluor2), ag(data.fluor2)*0, ag(data.fluor2)*0);
end

imshow( im, [] );
hold on;

rl = data.regs.regs_label;
ids = data.regs.ID;
nc = max( rl(:) );

props = regionprops( rl, 'PixelList' );

% Sets color depending on cell ID
for ii = 1:nc

id = ids(ii);

if ismember(id,ids1)
cc = 'b';
elseif ismember(id, ids2)
cc = 'r';
else
cc = 'y';
end

% Mask for current region
tmp = rl;
tmp(tmp ~= ii) = 0;

% Increase size of mask by 1 px and find boundary
se = strel('disk',1);
tmp2 = logical(imdilate(tmp,se));
[y,x] = find(tmp2 == 1);
k = boundary(x,y,1);


hold on;
skip = 1;
kk = k([1:skip:end]);
kk = kk([end-3:end,1:end,1:4]);

n = 1:numel(kk);
nn = 5:1:(numel(kk)-1);

% Interprets from pixel outline to smooth drawn outline
% xx = interp1( n, x(kk), nn,'spline' );
% yy = interp1( n, y(kk), nn,'spline' );

p = 0.1; %smaller value of p gives more smoothing
xx = fnval(csaps( n, x(kk),p), nn);
yy = fnval(csaps( n, y(kk),p), nn);


% Plots outline on phase image
plot( xx, yy, 'LineStyle','-','Color',cc,'LineWidth', .5 );

end

end
94 changes: 94 additions & 0 deletions viz/intMakeMultiChannel.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
function im = intMakeMultiChannel( data, FLAGS, CONST, clist, nc )

im = [];

if (FLAGS.f_flag == 0 && ~FLAGS.composite ) || ...
(FLAGS.phase_flag( FLAGS.f_flag +1 ) && ~FLAGS.composite) ...
|| (FLAGS.composite && FLAGS.include(1) );

if FLAGS.manual_lut(1) && ~isnan( FLAGS.lut_min(1) ) && ~isnan( FLAGS.lut_max(1))
minmax = [FLAGS.lut_min(1), FLAGS.lut_max(1)];
elseif FLAGS.gbl_auto(1) && isfield( clist, 'imRangeGlobal')
minmax = clist.imRangeGlobal(:,1);
else
minmax = intMakeMinMax( data.phase );
end

im = comp( {data.phase, minmax, FLAGS.level(1)} );
end

% if you are in fluorescence mode (f_flag) draw the fluor channels
if FLAGS.f_flag && CONST.view.falseColorFlag
ranger = FLAGS.f_flag;
elseif FLAGS.composite
ranger = find(FLAGS.include(2:(nc+1)));
elseif ~FLAGS.f_flag
ranger = [];
else
ranger = FLAGS.f_flag;
end

for ii = ranger;

flName = ['fl',num2str(ii),'bg'];

filtName = ['fluor',num2str(ii),'_filtered'];

if FLAGS.filt(ii) && isfield( data, filtName);
flourName = filtName;
else
flourName = ['fluor',num2str(ii)];
end

im_tmp = data.(flourName);

if FLAGS.filt(ii)
minmax = intMakeMinMax( im_tmp );

if isfield( data, flName )
minmax(1) = data.(flName);
end

elseif FLAGS.manual_lut(ii+1) && ~isnan( FLAGS.lut_min(ii+1) ) && ~isnan( FLAGS.lut_max(ii+1))
minmax = [FLAGS.lut_min(ii+1), FLAGS.lut_max(ii+1)];
elseif FLAGS.gbl_auto(ii+1) && isfield( clist, 'imRangeGlobal')
minmax = clist.imRangeGlobal(:,ii+1);
else
minmax = intMakeMinMax( im_tmp );

if isfield( data, flName )
minmax(1) = data.(flName);
end

end

if CONST.view.falseColorFlag && FLAGS.f_flag
cc = jet(256);
else
cc = CONST.view.fluorColor{ii};
end


command = {im_tmp, cc, FLAGS.level(ii+1)};

if FLAGS.log_view(ii)
command = {command{:}, 'log'};
else
command = {command{:}, minmax };
end

im = comp( {im}, command );


end










end

0 comments on commit a4f36ed

Please sign in to comment.