Skip to content

Commit

Permalink
added dark bg option
Browse files Browse the repository at this point in the history
  • Loading branch information
asafgal committed Jan 17, 2021
1 parent ed12ea6 commit 93408c5
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 10 deletions.
2 changes: 2 additions & 0 deletions antrax/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ def predict_images_file(self, imagefile, outfile=None, usepassed=False, report=F

names += [tracklet]

f.close()

if outfile is None:
outfile = os.path.join(self.outdir, 'autoids_' + str(m) + '.csv')

Expand Down
4 changes: 2 additions & 2 deletions antrax/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def solve(explist, *, glist: parse_movlist=None, movlist: parse_movlist=None, cl

def train(classdir, *, name='classifier', scratch=False, ne=5, unknown_weight=20, multi_weight=0.1, arch='small', modelfile=None,
target_size: to_int=None, crop_size: to_int=None, hsymmetry=False, aug_options='', hpc=False, hpc_options: parse_hpc_options={},
dry=False):
background='white', dry=False):
"""Train a blob classifier"""
hpc = hpc or ANTRAX_HPC

Expand All @@ -402,7 +402,7 @@ def train(classdir, *, name='classifier', scratch=False, ne=5, unknown_weight=2
f = glob(examplesdir + '/*/*.png')[0]
target_size = max(imread(f).shape)

c = axClassifier(name, nclasses=n, target_size=target_size, crop_size=crop_size, hsymmetry=hsymmetry,
c = axClassifier(name, nclasses=n, target_size=target_size, crop_size=crop_size, hsymmetry=hsymmetry, background=background,
unknown_weight=unknown_weight, multi_weight=multi_weight, modeltype=arch, json=modelfile)

c.save(classfile)
Expand Down
Binary file not shown.
7 changes: 6 additions & 1 deletion matlab/@tracklet/add_examples.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ function add_examples(trj,varargin)

ims = trj.get_image(tt);
msk = repmat(max(ims,[],3)==0,[1,1,3,1]);
ims(msk)=255;

if trj.Trck.get_param('segmentation_invert')
ims(msk)=0;
else
ims(msk)=255;
end

for i=1:size(ims,4)

Expand Down
1 change: 1 addition & 0 deletions matlab/@trhandles/default_params.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
prmtrs.segmentation_illum_correct = false;
prmtrs.segmentation_illum_correct_level = 0.9;

prmtrs.segmentation_invert = false;
prmtrs.segmentation_threshold = 0.14;

prmtrs.segmentation_IntensityFilter = false;
Expand Down
Binary file modified matlab/apps/antrax.mlapp
Binary file not shown.
Binary file modified matlab/apps/validate_classifications.mlapp
Binary file not shown.
2 changes: 1 addition & 1 deletion matlab/misc/applyMasktoIm.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function MaskedIm = applyMasktoIm(Im,Mask)
function MaskedIm = applyMasktoIm(Im,Mask,fillval)
% jonathan saragosti
% 02/18/15
% apply a binary mask to an image,
Expand Down
2 changes: 2 additions & 0 deletions matlab/misc/create_backgrounds.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ function create_backgrounds(Trck, pb)
switch method
case 'max'
bg = max(frames,[],4);
case 'min'
bg = min(frames,[],4);
case 'median'
bg = median(frames,4);
otherwise
Expand Down
16 changes: 13 additions & 3 deletions matlab/tracking/detect_blobs.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,14 @@ function detect_blobs(Trck,varargin)

%% Image segmentation

Z = imsubtract(BGS,frame_single);
if Trck.get_param('segmentation_invert')
Z = imsubtract(frame_single,BGS);
else
Z = imsubtract(BGS,frame_single);
end

Z = Z.*single(mask);

%Z = applyMasktoIm(Z,mask);

if Trck.get_param('segmentation_local_z_scaling')
Expand All @@ -69,7 +75,11 @@ function detect_blobs(Trck,varargin)
% threshold the image
if Trck.get_param('segmentation_use_max_rgb')
ZGRY = max(Z,[],3);
FGRY = min(frame,[],3);
if Trck.get_param('segmentation_invert')
FGRY = max(frame,[],3);
else
FGRY = min(frame,[],3);
end
else
ZGRY = rgb2gray(Z);
FGRY = rgb2gray(frame);
Expand Down Expand Up @@ -223,7 +233,7 @@ function detect_blobs(Trck,varargin)
sqsz = Trck.get_param('sqsz');

padded_label = padarray(ab.LABEL,[sqsz/2,sqsz/2]);
if Trck.get_param('segmentation_color_correction_for_classification')
if Trck.get_param('segmentation_color_correction_for_classification') && ~Trck.get_param('segmentation_invert')
padded_frame = padarray(frame_corrected,[sqsz/2,sqsz/2]);
else
padded_frame = padarray(frame_orig,[sqsz/2,sqsz/2]);
Expand Down
11 changes: 8 additions & 3 deletions scripts/classifier_test_jobfile.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#!/bin/bash
#SBATCH --job-name=ctest
#SBATCH --output=/ru-auth/local/home/agal/ctest1_%a.log
#SBATCH --output=/ru-auth/local/home/agal/logs/class_test_NAME__%a.log
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=8
#SBATCH --mail-type=ALL
#SBATCH --mail-user=agal@rockefeller.edu
#SBATCH --array=0-50%100
#SBATCH --array=1-NREP_%100

NAME="NAME_"
N="N_"
LOG="LOG_"
CLASSDIR="CLASSDIR_"
NE="NE_"

srun python /ru-auth/local/home/agal/code/anTraX/scripts/classifier_test.py /ru-auth/local/home/agal/scratch/Classifiers/A36_classifier_analysis -n 2000 --name n2000 --ne 100 --logfile /ru-auth/local/home/agal/classifier_test.log
srun python /ru-auth/local/home/agal/code/anTraX/scripts/classifier_test.py $CLASSDIR -n $N --name $NAME --ne $NE --logfile $LOGFILE

0 comments on commit 93408c5

Please sign in to comment.