Skip to content

Commit

Permalink
merged the dev_newInfo branch with master
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Wiggins committed Jun 19, 2018
2 parents 463ad73 + b6cb8b2 commit 8782968
Show file tree
Hide file tree
Showing 50 changed files with 3,024 additions and 884 deletions.
36 changes: 22 additions & 14 deletions Internal/ag.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [im,im_min,imax] = ag (im,imin,imax)
function [im,imin,imax] = ag (im,imin,imax)
% ag : autogain, it increases the contrast of image im, using imin and imax.
% It subtracts the the minimum from of the image, divides by the max and
% then normalizes to 255.
Expand Down Expand Up @@ -31,25 +31,33 @@

im = double(im);



im(isinf(im(:))) = nan;

if exist( 'imin', 'var') && ~isempty( imin )
im_min = imin;
if ~exist( 'imin', 'var') || isempty( imin )
imin = min( im(:) );
else
im_min = min(im(:));
imin = double( imin );
end

if ~exist( 'imax', 'var') || isempty(imax)
imax = max(im(:));

if ~exist( 'imax', 'var') || isempty( imax )
imax = max( im(:) );
else
imax = double( imax );
end

if imin == imax
if imin > 0
im = im/imax;
end
else
im = (im-imin)/(imax-imin);
end

% autogain and normalization to uint8
im = uint8(255*im);

im_max = imax-im_min;

% subtract min
im = im - double(im_min);


% autogain and normalization to uint8
im = uint8(255*im/double(im_max));

end
22 changes: 22 additions & 0 deletions Internal/intFixFields.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function CONST = intFixFields( CONST, CONST0 )
% This function adds fields that exist in CONST0 but do not exist in CONST
% to CONST
if isstruct( CONST0 )
C0n = fieldnames( CONST0 );

for ii = 1:numel( C0n )

if isfield( CONST, C0n{ii} )
CONST = setfield( CONST, C0n{ii}, ...
intFixFields( getfield( CONST, C0n{ii} ),...
getfield( CONST0, C0n{ii}) ) );
else
CONST = setfield( CONST, C0n{ii}, getfield( CONST0, C0n{ii}));
end

end
%else
% CONST = CONST0;
end

end
22 changes: 22 additions & 0 deletions Internal/intFixFileName.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function name_mod = intFixFileName( name, str_end)
% Fixes a file name by adding the suffix str_end if it doesn't already
% exist
if str_end(1) ~= '.'
str_end = ['.',str_end];
end

ns = numel( str_end );
nn = numel( name );

% check file name length
if ns > nn
name_mod = [ name, str_end];
elseif ~strcmp( name( [end-ns+1:end] ), str_end )
name_mod = [ name, str_end];
else
name_mod = [ name ];
end

end


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
24 changes: 24 additions & 0 deletions Internal/intImRead.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function im = intImRead(out_name)
% More flexible method for loading images... if the file is a mat file, it
% will load the image in that... else it uses imread
im = [];

if numel(out_name) > 4
if strcmp(out_name([end-3:end]), '.mat' )
tmp = load( out_name );
if isfield( tmp, 'im' );
im = tmp.im;
end
elseif strcmp(out_name([end-3:end]), '.tif' )
im = imread( out_name );
end
end


if numel(size(im)) > 2
disp('Images are in color - attempting to convert to monochromatic.');
im = convertToMonochromatic(im);
end
end


15 changes: 15 additions & 0 deletions Internal/intImWrite.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function intImWrite(im,out_name)
% More flexible metho of writing images. Can use save if the image name is
% .mat.
if numel( out_name ) > 4
if strcmp( out_name(end-3:end), '.mat' )
out_name = intFixFileName( out_name, '.mat' );
save( out_name, 'im' );
else
out_name = intFixFileName( out_name, '.tif' );
imwrite(uint16(im), out_name ,'tif','Compression', 'none');
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
2 changes: 2 additions & 0 deletions Internal/intShiftIm.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@

imOut = (real(ifft2(fftB).*exp(-1i*phase)));

%imOut2 = imtranslate( imIn, -out([4,3]),'FillValues', mean(imIn(:)));

end
52 changes: 52 additions & 0 deletions Internal/intShiftImMod.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
function imOut = intShiftIm( imIn, out )
%% intShiftIm: shifts image 'imIn' by the parameters in 'out'
% out is produced by intAlignIm( imA, imB, precision ).
%
% INPUT :
% imIn : input image
% out : output of intAlignIm,
% where the 3rd element is the row_shift and 4th and col_shift
%
% OUTPUT :
% imOut : shifted image
%
% Copyright (C) 2016 Wiggins Lab
% Written by Paul Wiggins.
% University of Washington, 2016
% 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/>.

%
% fftB = fft2(imIn); % fourier transform
%
% deltar = out(3); % net_row_shift in subpixel
% deltac = out(4); % net_col_shift in subpixel
%
% phase = 0;
% [nr,nc] = size(imIn); % nr : num of rows, nc : num of columns
% Nr = ifftshift(-fix(nr/2):ceil(nr/2)-1); % swaps the left and right halves
% Nc = ifftshift(-fix(nc/2):ceil(nc/2)-1);
% [Nc,Nr] = meshgrid(Nc,Nr);
%
% fftB = fftB.*exp(1i*2*pi*(deltar*Nr/nr+deltac*Nc/nc));
%
% imOut = (real(ifft2(fftB).*exp(-1i*phase)));
%
% This re-implementation uses the matlab built in imtranslate.


imOut = imtranslate( imIn, -out([4,3]),'FillValues', mean(imIn(:)));

end
8 changes: 4 additions & 4 deletions Internal/isRightNameFormat.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
% along with SuperSegger. If not, see <http://www.gnu.org/licenses/>.


contents = dir([dirname,filesep,'*.tif']);
contents = dir([dirname,filesep,'*.tif*']);
filenames = {contents.name}';

nameWithXy=regexpi(filenames,'t\d+xy\d+c\d+.tif','once');
nameWithoutXy=regexpi(filenames,'t\d+c\d+.tif','once');
nameWithoutt=regexpi(filenames,'xy\d+c\d+.tif','once');
nameWithXy=regexpi(filenames,'t\d+xy\d+c\d+.tif+','once');
nameWithoutXy=regexpi(filenames,'t\d+c\d+.tif+','once');
nameWithoutt=regexpi(filenames,'xy\d+c\d+.tif+','once');

numWithXy = sum(~cellfun('isempty',nameWithXy));
numWithoutXY = sum(~cellfun('isempty',nameWithoutXy));
Expand Down
10 changes: 5 additions & 5 deletions batch/BatchSuperSeggerOpti.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function BatchSuperSeggerOpti(dirname_,skip,clean_flag,res,startEnd,showWarnings
% align frames
if exist( dirname_, 'dir' )
if exist( [dirname_,filesep,'raw_im'] ,'dir') && ...
(numel(dir ([dirname_,filesep,'raw_im',filesep,'*.tif'])) || ...
(numel(dir ([dirname_,filesep,'raw_im',filesep,'*.tif*'])) || ...
exist([dirname_,filesep,'raw_im',filesep,'cropbox.mat'],'file'))
disp('BatchSuperSeggerOpti : images already aligned');
if exist([dirname_,filesep,'raw_im',filesep,'cropbox.mat'],'file')
Expand All @@ -128,7 +128,7 @@ function BatchSuperSeggerOpti(dirname_,skip,clean_flag,res,startEnd,showWarnings
else
crop_box_array = cell(1,10000);
end
elseif numel(dir ([dirname_,filesep,'*.tif']))
elseif numel(dir ([dirname_,filesep,'*.tif*']))
% check naming convention
if ~isRightNameFormat(dirname_)
disp('Images in incorrect naming format. Using convertImageNames to convert names.')
Expand All @@ -139,8 +139,8 @@ function BatchSuperSeggerOpti(dirname_,skip,clean_flag,res,startEnd,showWarnings
if CONST.align.ALIGN_FLAG
crop_box_array = trackOptiAlignPad( dirname_,...
CONST.parallel.parallel_pool_num, CONST);
movefile( [dirname_,filesep,'*.tif'], [dirname_,filesep,'raw_im'] ) % moves images to raw_im
movefile( [dirname_,'align',filesep,'*.tif'], [dirname_,filesep]); % moves aligned back to main folder
movefile( [dirname_,filesep,'*.tif*'], [dirname_,filesep,'raw_im'] ) % moves images to raw_im
movefile( [dirname_,'align',filesep,'*.tif*'], [dirname_,filesep]); % moves aligned back to main folder
rmdir( [dirname_,'align'] ); % removes _align directory
else
copyfile( [dirname_,filesep,'*.tif'], [dirname_,filesep,'raw_im'] ) % moves images to raw_im
Expand Down Expand Up @@ -251,7 +251,7 @@ function intProcessXY( dirname_xy, skip, nc, num_c, clean_flag, ...
% processor all the information it needs to process the images.

% Initialization
file_filter = '*.tif';
file_filter = '*.tif*';
verbose = CONST.parallel.verbose;

% get header to show xy position
Expand Down
13 changes: 8 additions & 5 deletions batch/convertImageNames.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ function convertImageNames(dirname, basename, timeFilterBefore, ...
% along with SuperSegger. If not, see <http://www.gnu.org/licenses/>.


images = dir([dirname,filesep,'*.tif']);
images = dir([dirname,filesep,'*.tif*']);

% directory to move original images
dirOriginal = [dirname,filesep,'original',filesep] ;
imagesInOrig = dir([dirOriginal,filesep,'*.tif']);
imagesInOrig = dir([dirOriginal,filesep,'*.tif*']);

elementsTime='t';
elementsXY ='xy';
Expand Down Expand Up @@ -87,10 +87,13 @@ function convertImageNames(dirname, basename, timeFilterBefore, ...
end

if isempty(imagesInOrig) % move original images
movefile([dirname,filesep,'*.tif'],dirOriginal); % move all images to dir original


movefile([dirname,filesep,'*.tif*'],dirOriginal); % move all images to dir original

end

images = dir([dirOriginal,filesep,'*.tif']);
images = dir([dirOriginal,filesep,'*.tif*']);

% go through every image
for j = 1: numel (images)
Expand Down Expand Up @@ -186,4 +189,4 @@ function convertImageNames(dirname, basename, timeFilterBefore, ...
numbers = str2double(pattern);
end

end
end
1 change: 1 addition & 0 deletions batch/processExp.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function processExp( dirname )
CONST.trackOpti.NEIGHBOR_FLAG = false; % calculate number of neighbors (default = false)
CONST.imAlign.AlignChannel = 1; % change this if you want the images to be aligned to fluorescence channel

CONST.view.fluorColor = {'y','r','b'};

%% Skip Frames for Segmentation
% For fast time-lapse or slow growth you can skip phase image frames
Expand Down
1 change: 1 addition & 0 deletions batch/superSeggerGui.m
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ function end_step_CreateFcn(hObject, eventdata, handles)

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
Loading

0 comments on commit 8782968

Please sign in to comment.