Last edited on 2009-01-30 03:07:28 by stolfi Processing the IAB-2002 fragment pictures 04 - Segmenting the images ====================================================================== % TO DO LATER % % Before doing this step, check the segmentation images at % UFF, and create touched-up versions of the -s.jpg images (-t.jpg) to % fix bad segmentations. Also add extra seed points on the stage paper, % on the mirror, and on the green monoliths. UPDATING THE FRAGMENT NUMBERS AND POSITIONS Futher numbers were collected by HCGL's students at UFF in a different format. Here is the conversion from UFF to Unicamp format: pushd coords cat fragcenters-uff-old.txt \ | ../tools/convert-fragcenters-uff-unicamp \ -f ../tools/read-table.gawk \ -v table=../raw-to-sorted.tbl \ > fragcenters-uff.txt popd This data should eventually be merged into fragcenters.txt, replacing the old invented fragment numbers. Here is the first try of that: pushd coords cat fragcenters.txt \ | ../tools/replace-fragment-numbers \ > fragcenters-renumbered.txt popd The old "{F}.fctrs" and "{F}-f.jpg" files were renamed temporarily "{F}-o.fctrs" and "{F}-o-f.jpg". Then we executed tools/write-fragcenters fragcenters-renumbered.txt The script creates files "{F}.fctrs" for each image "{F}.jpg" listed in "fragcenters.txt", and also a browse-size image "{F}-f.jpg" showing the fragment centers and numbers. Comparing the two: find ./ -name '*-n.jpg' -print | grep stds | sort > .tmp display -title '%d/%f' `cat .tmp` Unfortunately the UFF data is too buggy and parctically useless. It did reveal some errors in the original data though. Undid the renaming. Checking whether there was any "{F}.fctrs" not generated by the script: find ./ -name '*-o.fctrs' -print | sort > .ooo find ./ -name '*.fctrs' -print | sort > .ttt bool 1-2 .ttt .ooo > .nnn cat .ooo | sed -e 's:-o.fctrs:.fctrs:g' | sort > .sss diff -Bb .sss .nnn SEGMENTING THE IMAGES Preliminary segmentation of the images is done by the script "segment-image" in the "tools" directory. Collecting the names of images that are worth segmenting: find TEC/ PUB/ PRE/ \ -type d \( -name 'stds' -o -name 'mirr' \) \ -print \ > .dirs find `cat .dirs` \ -type f -name '*-s.jpg' \ -print \ | sed -e 's/-s[.]jpg//' \ > .images Segmenting them: foreach img ( `cat .images | sed -e 's:[#].*$::g'` ) echo "=== ${img} ====================================" nice tools/segment-image ${img} end COLLECTING ALL IMAGES OF ALL FRAGMENTS The goal here is to bring together all images of the same fragment, and display them in a format that makes it easy to read off the official fragment number. Create table listing all extracted fragment images and the corresponding fragment names: find {PRE,TEC,ETC,PUB}/ \ -name '*.seeds' \ -print \ > .seedfiles /bin/rm -f fragimage-to-fragname.tbl touch fragimage-to-fragname.tbl foreach sf ( `cat .seedfiles` ) set img = `echo ${sf:r} | sed -e 's:-s$::g'` echo $sf $img cat $sf \ | gawk -v img=${img} \ ' /[=]/{ \ num=$6; nam=$8; \ if ((num+0) > 1) \ { printf "%s-seg-%s.png %s\n", img, num, nam; } \ } ' \ >> fragimage-to-fragname.tbl end Create list of fragments: cat fragimage-to-fragname.tbl \ | gawk '//{print $2;}' \ | sort | uniq \ > .fragments Create the per-fragment directories: mkdir FRG foreach frg ( `cat .fragments` ) mkdir FRG/${frg} end Now make, for each fragment, a list of all segment images of that fragment: /bin/rm -f FRG/*/seg-images.dir cat fragimage-to-fragname.tbl \ | sort -b +1 -2 \ | gawk \ ' BEGIN { ofrg = ""; } \ // { img=$1; frg=$2; \ if (frg != ofrg) \ { if (ofrg != "") { close(ofile); } \ ofrg = frg; ofile = ("FRG/" frg "/seg-images.dir"); \ } \ printf "%s\n", img >> ofile; \ next; \ } \ END { if (ofrg != "") { close(ofile); } } \ ' EXTRACTING IMAGES OF INDIVIDUAL FRAGMENTS Extracting individual fragments: foreach img ( `cat .images | sed -e 's:[#].*$::g'` ) echo "=== ${img} ====================================" nice tools/extract-segments ${img} end (This step should be improved. The generation of the full-scale fragment masks from the IFT label map takes too long and repeats the same work many times. Consider some special-purpose program to generate those masks.) GATHERING ALL IMAGES OF EACH FRAGMENT Check whether we missed something: find {PRE,TEC,ETC,PUB}/ \ -name '*-seg-[0-9][0-9][0-9].png' \ -print \ | sort \ > .segimages cat fragimage-to-fragname.tbl \ | gawk ' //{print $1;} ' \ | sort \ > .expected-segimages bool 1-2 .expected-segimages .segimages > .missing-images bool 1-2 .segimages .expected-segimages > .spurious-images echo ' '; wc -l .expected-segimages .segimages .missing-images .spurious-images echo "spurious segmented fragment images: " cat .spurious-images Now merge all images of each fragment into a single image: foreach frg ( `cat .fragments` ) tools/gather-fragment-images -show ${frg} end