% demo3D16
%
% This method shows how to preprocess raw images to use as input for
% CellOrganizer. The main idea behind this demo is to show the user they
% can use their own binary images from raw experimental data they can use
% to synthesize protein patterns. The current demo assumes the resolution
% of the images is the same as the images that were used to train the
% protein model

% Created: Ivan E. Cao-Berg
%
% Copyright (C) 2012-2015 Murphy Lab
% Lane Center for Computational Biology
% School of Computer Science
% Carnegie Mellon University
%
% November 8, 2012 Changed the location of the input image
%
% This program 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 2 of the License,
% or (at your option) any later version.
%
% This program 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 this program; if not, write to the Free Software
% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
% 02110-1301, USA.
%
% For additional information visit http://murphylab.web.cmu.edu or
% send email to murphy@cmu.edu

curr_path = which('demo3D16.m');
curr_path = curr_path(1:end-10);
cd(curr_path);
clear param

try
 state = rng(3);
catch
 state = RandStream.create('mt19937ar','seed',3);
 RandStream.setDefaultStream(state);
end

outputDirectory = pwd;
param = [];
param.targetDirectory = outputDirectory;
param.prefix = 'synthesizedImages';
param.numberOfSynthesizedImages = 1;
param.compression = 'lzw';
param.microscope = 'none';
param.sampling.method = 'disc';
param.verbose = true;
param.debug = false;
param.display = false;
param.synthesis = 'all';

param.resolution.cell = [0.05,0.05,0.2];
downsample = [5 5 1];
param.resolution.cell = param.resolution.cell.*downsample;

%icaoberg 11/8/2012
directory = [ '../../../images/HeLa/3D/raw/LAMP2' ];
dna_image_file = [ directory filesep 'cell1_ch0_t1.tif' ];
cell_image_file = [ directory filesep 'cell1_ch1_t1.tif' ];
prot_image_file = [ directory filesep 'cell1_ch2_t1.tif' ];
mask_image_file = [ directory filesep 'cell1_mask_t1.tif' ];

%D. Sullivan 7/8/13
%Adding required parameters
param = set_temp_result_folders( param );
param.train.flag = 'framework';

[ param.instance.nucleus, param.instance.cell ] = ...
    seg_cell_and_nucleus( dna_image_file, ...
    cell_image_file, ...
    prot_image_file, ...
    mask_image_file, ...
    downsample, param.display, param );

slml2img( {'../../../models/3D/lamp2.mat'}, param );
