next up previous contents
Next: mb_imgfeatures.m Up: Feature Extraction - ad Previous: Feature Extraction - ad

mb_imgfeatures.pl

 
#! /usr/bin/perl -s
#
# $Id: mb_imgfeatrues.pl_tmp,v 1.1 1999/06/26 14:17:12 boland Exp $
#
# mb_imgfeatures.pl 
#           -filelist='filename'
#
# 'filename' is the file containing the list of images to be processed
#    (see files_to_process.pl for generating this list).
#

# Confirm the presence of required arguments...
#


unless ($filelist =~ /\w/) {
    die("filelist must be defined on the command line.") ;
}

require("$filelist") ;

$numimagefiles = @imagefiles ;
$numcropfiles  = @cropfiles ;
$numdnafiles   = @dnafiles ;

unless(($numimagefiles == $numcropfiles) &&  
       ($numcropfiles == $numdnafiles)) {
    die("The number of image files ($numimagefiles), crop files 
($numcropfiles)  and dna files ($numdnafiles) is not the same.") ;
}


#
# Insert the date into the output file
#
#
# Generate the output file name for the features
#
$imagefiles[0] =~ /^[a-z]*([0-9a-z]+\.[0-9a-z]+)\.[0-9]{2}[-\.]/ ;
# $1 matches the string from the first set of parentheses in
#   the previous pattern match.
$featurefile = $1 ;
chop($timenow = `date '+%Y%m%d'`) ;
$featurefile = $featurefile . '.' . $timenow . '.features' ;

print STDOUT <<_EOF
fileid = fopen(\'$featurefile\', 'w') ;
if (~fileid)
    error('Unable to open the output file') ;
end 

_EOF
;

#
# Add variables to the M-file
#
print STDOUT <<_EOF

%
% Values for shifting the DNA image to align with the localization image
%
xshift = $xshift ;
yshift = $yshift ;

_EOF
;


#
# Process all image files
#
for ($i=0 ; $i < $numimagefiles ; $i++) {
    ($imagefiles[$i] =~ /\.([0-9]{2})[-\.]/) ;
    $imagenum = $1 ;

    ($cropfiles[$i] =~ /\.([0-9]{2})[-\.]/) ;
    $cropnum = $1 ;

    ($dnafiles[$i] =~ /\.([0-9]{2})[-\.]/) ;
    $dnanum = $1 ;

    unless(($imagenum eq $cropnum) && ($cropnum eq $dnanum)) {
	die("The image ($imagenum), crop ($cropnum), and/or dna 
    ($dnanum) file names do not match.") ;
    }
	
print STDOUT <<_EOF
%
% File: $imagefiles[$i]
%
% fprintf('%s...\\n', '$imagefiles[$i]') ;
image = mb_tclread('$imagedir/$imagefiles[$i]') ;
cropimage = imread('$cropdir/$cropfiles[$i]') ;
dnaimage = mb_tclread('$dnadir/$dnafiles[$i]') ;


imagesub = mb_imgbgsub(image, 'common') ;
imagemask = mb_threshcrop(imagesub, cropimage) ;
imageproc = roifilt2(0,imagesub, ~imagemask) ;
imagehull = mb_imgconvhull(imagemask) ;

dnasub = mb_imgbgsub(dnaimage, 'common') ;
dnamask = mb_threshcrop(dnasub, cropimage) ;
dnaproc = roifilt2(0,dnasub, ~dnamask) ;
% dnahull = mb_imgconvhull(dnamask) ;

[imagenames, imagevalues] = mb_imgfeatures(imageproc, ...
		  mb_imgshift(dnaproc,xshift,yshift)) ;

[hullnames, hullvalues] = mb_hullfeatures(imageproc, imagehull) ;

[znames, zvalues] = mb_zernike(imageproc, 12, 150) ;

tnames = {'angular_second_moment' 'contrast' 'correlation' ...
	  'sum_of_squares' 'inverse_diff_moment' 'sum_avg' ...
	  'sum_var' 'sum_entropy' 'entropy' 'diff_var' ...
	  'diff_entropy' 'info_measure_corr_1' 'info_measure_corr_2'} ;
tvalues = mb_texture(uint8(mb_imgscale(imageproc)*255)) ;

[edgenames, edgevalues] = mb_imgedgefeatures(imageproc) ;

featurenames = [imagenames, hullnames, znames, tnames, edgenames] ;
featurevalues = [imagevalues, hullvalues, abs(zvalues), tvalues(1:13,5)' ...
                 edgevalues] ;

%
% Write the current file name, the feature names, and the feature values
%
fprintf(fileid, '#\\t%s\\t', '$imagefiles[$i]') ;
for i=1:length(featurenames)
  fprintf(fileid, '%s\\t', char(featurenames(i))) ;
end
fprintf(fileid, '\\n', '') ;
fprintf(fileid, '%d\\t', double(featurevalues)) ; 
fprintf(fileid, '\\n', '') ;

_EOF

}

print STDOUT <<_EOF
fclose(fileid) ;
quit

_EOF
;


 



Copyright ©1999 Michael V. Boland
1999-09-18