Hi I am a newbe to bash programming and need some help. I am building a pipeline for image processing. I would like to be able to take the png images in a folder and pass them to clusterImage.pl once that is done I would like to then pass the outputted file to seperateObjects.pl the outputted file is of the same name but has kmeansOutput.all.matrix attached to the end. Below is what I have so far, but it is not working.
Any help would be greatly appreciated. Thank you
#!/bin/bash
#This script will take in an image and a matrix file.
#The output will be an image and a matrix file.
list=`ls *.png`
for i in $list
do
$file="./$list"
$image_array = $list
echo $file
#Cheching to see if the file exists.
for((j=0;j<=i;j++))
do
if [ -e image_array[j] ]; then
echo $file
echo "Begining processing"
#Take in an image and create a matrix from it.
perl clusterImage.pl SampleImage.png
#Take in a matrix and draw a picture showing the centers of all
#of the colonies.
perl seperateObjects.pl SampleImage.png.kmeansOutput.all.matrix
echo "Ending processing"
else
echo "There is an issue"
fi
done
done
I see a few problems (or potential improvements) with your code:
for i in $listbecause you never use$iin the script – that results in just doing the same thing over and over again (the same number of times as the number of.pngfiles in the directory)*.png.perl clusterImage.plon each.pngfile in the directory… or did you? It’s kind of hard to tell. Edit your question to explain more clearly what you mean to do, and I can edit my answer accordingly.You can use short-circuiting, as they call it, instead of an
ifstatement:[ -f file.png ] && echo "file exists"is shorter thanIf I understand what you’re trying to do (and I’m not sure I do), I think this might work for you. For each image in the directory, this will run
perl clusterImage.pl <name_of_image.png>andperl separateObjects.pl <name_of_image.png>.kmeansOutput.all.matrix.