[GRASS-SVN] r68661 - sandbox/bo/i.segment.gsoc2016/i.segment
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jun 9 20:01:30 PDT 2016
Author: hao2309
Date: 2016-06-09 20:01:30 -0700 (Thu, 09 Jun 2016)
New Revision: 68661
Modified:
sandbox/bo/i.segment.gsoc2016/i.segment/iseg.h
sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c
sandbox/bo/i.segment.gsoc2016/i.segment/open_files.c
sandbox/bo/i.segment.gsoc2016/i.segment/parse_args.c
Log:
change some mistakes, create bands_seg2 in openfile.c
Modified: sandbox/bo/i.segment.gsoc2016/i.segment/iseg.h
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/iseg.h 2016-06-10 01:48:56 UTC (rev 68660)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/iseg.h 2016-06-10 03:01:30 UTC (rev 68661)
@@ -59,7 +59,7 @@
int mb;
/* ===parameters for ms_setting=== */
- double ms_bandwidth; /* "Moving window radiuns (1-32 in number of pixel) for mean shift" */
+ double ms_spatial_bandwidth; /* "Moving window radiuns (1-32 in number of pixel) for mean shift" */
double ms_range_bandwidth; /* Nomarlized range bandwidth for mean shift */
char *ms_suffix; /* a suffix to be appended to the input bands when writing out shifted band values */
/* ===end parameters for ms_setting=== */
Modified: sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c 2016-06-10 01:48:56 UTC (rev 68660)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c 2016-06-10 03:01:30 UTC (rev 68661)
@@ -53,8 +53,7 @@
globals->bands_out = &globals->bands_seg2;
/*window size in pixel number*/
- int n_bands = globals->nbands;
- int window_size = globals->ms_bandwidth*2+1;
+ int window_size = globals->ms_spatial_bandwidth*2+1;
alpha2 = globals->alpha * globals->alpha;
t = 0;
@@ -96,11 +95,11 @@
if (!(FLAG_GET(globals->candidate_flag, row, col)))
continue;
/* left bound of the window */
- int window_row_north = row - globals->ms_bandwidth;
+ int window_row_north = row - globals->ms_spatial_bandwidth;
/* right bound of the window */
int window_row_south = window_row_north + window_size;
/* upper bound of the window */
- int window_col_west = col - globals->ms_bandwidth;
+ int window_col_west = col - globals->ms_spatial_bandwidth;
/* lower bound of the window */
int window_col_east = window_col_west + window_size;
@@ -117,22 +116,20 @@
if (window_col_east > globals->col_max){
window_col_east = globals->col_max;
}
+
/* calculate new band values */
- double sum_of_weights[n_bands];
- memset(sum_of_weights,0,(n_bands)*sizeof(double));
- double px_new_val[n_bands];
- memset(px_new_val,0,(n_bands)*sizeof(double));
+ double sum_of_weights = 0;
+ double *px_new_val = G_malloc(sizeof(double) * globals->nbands);
/* start of the moving window */
for (int current_window_row = window_row_north;current_window_row<window_row_south;current_window_row++){
for (int current_window_col = window_col_west;current_window_col<window_col_east;current_window_col++){
- double weight[n_bands];
- memset(weight,1,(n_bands)*sizeof(double));
+ double weight = 1;
/* adapt initial spatial and range bandwidths */
double distance2 = pow((current_window_row - row),2)+pow((current_window_col - col),2);
- if (distance2 <= pow(globals->ms_bandwidth,2)){
+ if (distance2 <= pow(globals->ms_spatial_bandwidth,2)){
/* get the current pixel value */
- Segment_get(&globals->bands_seg, (void *)Rin.mean,row, col);
+ Segment_get(globals->bands_in, (void *)Rin.mean,row, col);
/* get the current moving window pixel value */
Segment_get(&globals->bands_seg, (void *)Rwin.mean,current_window_row, current_window_col);
@@ -140,9 +137,9 @@
if ((globals->calculate_similarity)(&Rin, &Rwin, globals) <= (globals->ms_range_bandwidth * globals->ms_range_bandwidth)){
int n = globals->nbands - 1;
do{
- weight[n_bands] *=gauss_kernel(pow((Rin.mean[n_bands]-Rwin.mean[n_bands]),2),globals->ms_range_bandwidth);
- sum_of_weights[n_bands] += weight[n_bands];
- px_new_val[n_bands] += Rwin.mean[n_bands]*weight[n_bands];
+ weight *=1;/* later can apply gaussian kernal */
+ sum_of_weights += weight;
+ px_new_val[n] += Rwin.mean[n]*weight;
} while(n--);
}
}
@@ -151,8 +148,13 @@
/* write the output to bands_out*/
- Rout.mean = px_new_val;
- Segment_put(&globals->bands_seg, (void *)Rout.mean, row, col);/* Segment_put(&globals->bands_seg2, (void *)Rout.mean, row, col); */
+ int n = globals->nbands - 1;
+ do{
+ Rout.mean[n] = px_new_val[n];
+ Rout.mean[n] /= sum_of_weights;
+ }while(n--);
+ Segment_put(globals->bands_out, (void *)Rout.mean, row, col);
+ /* Segment_put(&globals->bands_seg2, (void *)Rout.mean, row, col); */
/* if the squared difference between old and new band values
@@ -183,7 +185,7 @@
for (i = globals->row_min; i < globals->row_max; i++){
for (j = globals->col_min; j < globals->col_max; j++) {
Segment_get(&globals->bands_seg, (void *)R_prt.mean,i, j);
- G_message(_("\t%.2f"),R_prt.mean);
+ G_message(_("\t%.2f"),R_prt.mean[0]);
}
}
}
\ No newline at end of file
Modified: sandbox/bo/i.segment.gsoc2016/i.segment/open_files.c
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/open_files.c 2016-06-10 01:48:56 UTC (rev 68660)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/open_files.c 2016-06-10 03:01:30 UTC (rev 68661)
@@ -83,6 +83,7 @@
globals->max_diff = 1;
globals->max_diff = (*globals->calculate_similarity) (&Ri, &Rk, globals);
}
+
/* ********** find out file segmentation size ************ */
G_debug(1, "Calculate temp file sizes...");
@@ -129,7 +130,7 @@
(&globals->bands_seg, G_tempfile(), globals->nrows, globals->ncols, srows,
scols, inlen, nseg) != 1)
G_fatal_error("Unable to create input temporary files");
-
+
if (Segment_open
(&globals->rid_seg, G_tempfile(), globals->nrows, globals->ncols, srows,
scols, outlen, nseg * 2) != 1)
@@ -173,6 +174,13 @@
(void *)globals->bands_val, row, col) != 1)
G_fatal_error(_("Unable to write to temporary file"));
+ /* add globals->bands_seg2 when using mean shift */
+ if (globals->method == ORM_MS){
+ if(Segment_put(&globals->bands_seg2, &globals->bands_seg, row, col) !=1);
+ G_fatal_error(_("Unable to initiate the shift-value band for mean-shift"));
+ }
+
+
if (!is_null) {
if (!globals->seeds) {
/* sequentially number all cells with a unique segment ID */
@@ -215,6 +223,9 @@
/* bounds/constraints */
+
+
+
Rast_set_c_null_value(&globals->upper_bound, 1);
Rast_set_c_null_value(&globals->lower_bound, 1);
Modified: sandbox/bo/i.segment.gsoc2016/i.segment/parse_args.c
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/parse_args.c 2016-06-10 01:48:56 UTC (rev 68660)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/parse_args.c 2016-06-10 03:01:30 UTC (rev 68661)
@@ -44,7 +44,7 @@
/* =========================parameters for ms_setting====================== */
ms_spatial_bandwidth = G_define_option();
- ms_spatial_bandwidth->key = "ms_bandwidth";
+ ms_spatial_bandwidth->key = "ms_spatial_bandwidth";
ms_spatial_bandwidth->type = TYPE_DOUBLE;
ms_spatial_bandwidth->required = NO;
ms_spatial_bandwidth->answer = "2";
More information about the grass-commit
mailing list