/* * Khoros: $Id$ */ #if !defined(__lint) && !defined(__CODECENTER__) static char rcsid[] = "Khoros: $Id$"; #endif /* * Copyright (C) 1997, INPE. Sergio Donizete Faria, Gerald Jean Francis Banon * All rights reserved. See $K_PROG/repos/license/License. */ /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<< >>>> >>>> Main program for ksmincbmed >>>> >>>> Private: >>>> main >>>> >>>> Static: >>>> Public: >>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<< */ #include "ksmincbmed.h" clui_info_struct *clui_info = NULL; /*----------------------------------------------------------- | | Routine Name: main() - Sum of Minima Normalized by Median | | Purpose: main program for ksmincbmed | | Input: | char *clui_info->i_img_file; {Search image} | int clui_info->i_img_flag; {TRUE if -i_img specified} | | char *clui_info->t_img_file; {Template extracted from reference image} | int clui_info->t_img_flag; {TRUE if -t_img specified} | | char *clui_info->o_img_file; {Resulting output image from sum of minima} | int clui_info->o_img_flag; {TRUE if -o_img specified} | | Output: | Returns: | | Written By: Sergio Donizete Faria | Date: July 1, 1997 | Modifications: | ------------------------------------------------------------*/ int main( int argc, char **argv) { /* -main_variable_list */ kobject src; /* source object - input search image */ kobject template; /* source object - input template image */ kobject dest; /* destination object - output image */ kobject src_median ; /* destination object - source median */ kobject template_median;/* destination object - template median */ int src_width; /* input image width (num cols) */ int src_height; /* input image height (num rows) */ int src_depth; /* depth and time give number of input images */ int src_time; int src_bands; /* number of bands per input image */ int template_width; /* template image width (num cols) */ int template_height; /* template image height (num rows) */ int template_depth; /* depth and time give number of template images */ int template_time; int template_bands; /* number of bands per template image */ int num_row_template; int num_col_template; int size_template; int rep, num_regions; int h, i, j, k, n; int i0, i1, i2, k0, k1; int hh, ii, jj, kk; int ii0, ii1, kk0, kk1; int index0, index01, index1, index2, aux1; int cen_win_src, cen_win_template; long dif_src; long sum_min; long *template_data=NULL; long *template_median_data=NULL; long *src_data=NULL; long *src_median_data=NULL; long *dest_data=NULL; /* -main_variable_list_end */ khoros_init(argc, argv, "MATCHING", PRODUCT_RELEASE_DATE, PRODUCT_RELEASE_NAME, PRODUCT_RELEASE_VERSION, PRODUCT_RELEASE_MAJOR, PRODUCT_RELEASE_MINOR, "$MATCHING/objects/kroutine/ksmincbmed"); kexit_handler(ksmincbmed_free_args, NULL); /* -main_get_args_call */ kclui_init("MATCHING", "ksmincbmed", KGEN_KROUTINE, &clui_uis_spec, ksmincbmed_usage_additions, ksmincbmed_get_args, ksmincbmed_free_args); /* -main_get_args_call_end */ /* -main_before_lib_call */ /* * Open the source (src and template) and destination (dest) data * objects using kpds_open_input_object and kpds_open_output_object * calls. These calls will open the source and destination data object * with the flags set correctly. If an open fails, report the error * using kerror, close opened objects if necessary, and exit the program * using kexit call. */ if ((src = kpds_open_input_object (clui_info->i_img_file)) == KOBJECT_INVALID) { kerror(NULL, "ksmincbmed", "Cannot open source object src."); kexit(KEXIT_FAILURE); } if ((template = kpds_open_input_object (clui_info->t_img_file)) == KOBJECT_INVALID) { kerror(NULL, "ksmincbmed", "Cannot open source object template."); kexit(KEXIT_FAILURE); kpds_close_object(src); } if ((dest = kpds_open_output_object (clui_info->o_img_file)) == KOBJECT_INVALID) { kerror(NULL, "ksmincbmed", "Cannot open destination object."); kpds_close_object(src); kpds_close_object(template); kexit(KEXIT_FAILURE); } if ((src_median = kpds_create_object ()) == KOBJECT_INVALID) { kerror(NULL, "ksmincbmed", "Cannot create object src_median."); kexit(KEXIT_FAILURE); } if ((template_median = kpds_create_object ()) == KOBJECT_INVALID) { kerror(NULL, "ksmincbmed", "Cannot create object template_median."); kexit(KEXIT_FAILURE); } /* * Copy the search image object (src) to objects dest and src_median. * If the copy function fails, report the error and exit. The object * will be closed by kexit (). Since, the exit status is KEXIT FAILURE * the output object will not be writen to a perminent transport. */ if (! kpds_copy_object (src, dest)) { kerror(NULL, "ksmincbmed", "kpds_copy_object failed"); kexit(KEXIT_FAILURE); } if (! kpds_copy_object (src, src_median)) { kerror(NULL, "ksmincbmed", "kpds_copy_object failed"); kexit(KEXIT_FAILURE); } /* * Copy the image object (template) to object template_median. * If the copy function fails, report the error and exit. The object * will be closed by kexit (). Since, the exit status is KEXIT FAILURE * the output object will not be writen to a perminent transport. */ if (! kpds_copy_object (template, template_median)) { kerror(NULL, "ksmincbmed", "kpds_copy_object failed"); kexit(KEXIT_FAILURE); } /* * Get the KPDS_VALUE_SIZE attribute of the source object (src) which * provides the information about number of data elements in each * direction of source object. */ if (! kpds_get_attribute (src, KPDS_VALUE_SIZE, &src_width, &src_height, &src_depth, &src_time, &src_bands)) { kerror(NULL, "ksmincbmed", "kpds_get_attribute failed for KPDS_VALUE_SIZE"); kexit(KEXIT_FAILURE); } /* * Get the KPDS_VALUE__SIZE attribute of the template object which * provides the information about number of data elements in each * direction of this object. */ if (! kpds_get_attribute (template, KPDS_VALUE_SIZE, &template_width, &template_height, &template_depth, &template_time, &template_bands)) { kerror(NULL, "ksmincbmed", "kpds_get_attribute failed for KPDS_VALUE_SIZE"); kexit(KEXIT_FAILURE); } /* * Specifying the size of the region to process by selection a set of * rows from the source image as the region process. * Set this region size to: * - src_width = width of region (width source image) * - template_height = height of region * - template_depth = depth size of region * - template_time = time size of region * - template_bands = number of bands in the region */ if (! kpds_set_attribute (src, KPDS_VALUE_REGION_SIZE, src_width, template_height, template_depth, template_time, template_bands)) { kerror("NULL", "ksmincbmed", "kpds_get_attribute failed for KPDS_VALUE_REGION_SIZE"); kexit(KEXIT_FAILURE); } if (! kpds_set_attribute (dest, KPDS_VALUE_REGION_SIZE, src_width, template_height, template_depth, template_time, template_bands)) { kerror("NULL", "ksmincbmed", "kpds_get_attribute failed for KPDS_VALUE_REGION_SIZE (dest)"); kexit(KEXIT_FAILURE); } /* * Call routine to calculte the median of source image and template * image. */ num_row_template = template_height; num_col_template = template_width; rep = 1; if (!limedian(src, num_col_template, num_row_template, rep, src_median)) kexit(KEXIT_FAILURE); if (!limedian(template, num_col_template, num_row_template, rep, template_median)) kexit(KEXIT_FAILURE); /* *********************************************************************** * Major loop for processing * *********************************************************************** */ /* * Outer loops: variable h and i are the number of images in input * object. */ cen_win_template = (template_height * template_width)/2; for (hh = 0; hh < src_time; hh++) { for (ii = 0; ii < src_depth; ii++) { /* * 1st Middle loop: variable is the number of bands (elements) * to process. * - src_bands = number of bands (elements) per image in source * object */ for ( kk = 0; kk < src_bands; kk++) { /* * Get a region of template data. */ kpds_set_attribute(template,KPDS_VALUE_POSITION,0,0,ii,hh,kk); template_data = (long *)(kpds_get_data(template, KPDS_VALUE_ALL, template_data)); if (template_data == NULL) { kerror("NULL", "ksmincbmed", "kpds_get_data failed for KPDS_VALUE_ALL (template)."); kexit(KEXIT_FAILURE); } kpds_set_attribute(template_median, KPDS_VALUE_POSITION, 0, 0, ii, hh, kk); template_median_data = (long*)(kpds_get_data(template_median, KPDS_VALUE_ALL, template_median_data)); if (template_median_data == NULL) { kerror("NULL", "ksmincbmed", "kpds_get_data failed for KPDS_VALUE_ALL (template_median)."); kexit(KEXIT_FAILURE); } size_template = template_height * template_width; for (i2 = 0; i2 < size_template ; i2++) { template_data[i2] = template_data[i2] - template_median_data[cen_win_template]; } /* * 2nd Middle loop: variable is the number of regions to * process * - num_regions = number of rows (height) of source object */ num_regions = src_height; jj = 0; for (ii1 = template_height - 1; ii1i_img_file); kfree_and_NULL(clui_info->t_img_file); kfree_and_NULL(clui_info->o_img_file); kfree_and_NULL(clui_info); } /* -free_handler_additions */ /* -free_handler_additions_end */ }