#!/bin/csh
#mount GE tape before starting this script!
#
# Copyright (c) 1996 Matthew Belmonte
#
# 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# If you find this program useful, please send mail to Matthew Belmonte.
# <mkb4@Cornell.edu>.  If you base a publication on data processed by this
# program, please notify Matthew Belmonte and acknowledge him in your
# publication.
#
#EXTRACT AND CONVERT GE IMAGES
mkdir TapeDump
cd TapeDump
tar xvf /dev/tapens 
cd *
cd *
mv 004 ../../..
cd ../../..
rm -r TapeDump
mkdir data
cd data
mkdir PD
mkdir T2
cd ..
echo name_of_other_sequence will be T2 
~sch/bin/gecon 004 PD 112 -v
cd data
mv * ..
cd ..
rmdir data

#CONSTRUCT A PD-T2+50 HYBRID IMAGE SET
cp ~sch/data/lesion/_dimensions T2
set FILES=`/bin/ls PD`
set zsize=`echo $FILES | /bin/wc`
echo Edit _dimensions and make sure zsize is $zsize[2] and interps is 3 
unset zsize
sleep 4
vi T2/_dimensions
~sch/brian/pdmt2 T2 PD PD-T2 d on

#MIRROR-REVERSE ALL IMAGES TO CORRECT FOR REVERSAL ARTIFACT
mkdir if_PD-T2
foreach slice ($FILES)
	/usr/sbin/iflip PD-T2/$slice if_PD-T2/$slice y
end
rm -r PD-T2
cp T2/_dimensions if_PD-T2

#MANUALLY SEPARATE BRAIN FROM SURROUNDING TISSUE
~sch/bin/brnrmvl if_PD-T2 Brain 1
echo Interrupt NOW if brnrmvl died
set FILES=`/bin/ls Brain`
cp if_PD-T2/_dimensions Brain
sleep 4
echo decrease zsize to discard any non-brain slices 
sleep 4
vi Brain/_dimensions

#INTERPOLATE BETWEEN SCAN SLICES
~belmonte/bin/boundary_interpolate Brain if_PD-T2
rm -r if_PD-T2

echo Now you must use imged to white out the lesioned area on A COPY OF
echo the image set, then use thrsh to black out everything else, and then
echo add to merge the whited-out area into the original image set.  In
echo VoxelView_GT, use Partition Selection (254) and Set Background Color
echo (0,0,0) to generate an image of the lesion area that is in register
echo with the brain image, then use add to merge these two snapshots.
