[GRASS-SVN] r68650 - sandbox/bo/i.segment.gsoc2016/i.segment
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jun 8 20:39:23 PDT 2016
Author: hao2309
Date: 2016-06-08 20:39:23 -0700 (Wed, 08 Jun 2016)
New Revision: 68650
Modified:
sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c
Log:
updated the multi-band than then previous single band senario
Modified: sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c 2016-06-09 01:23:37 UTC (rev 68649)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c 2016-06-09 03:39:23 UTC (rev 68650)
@@ -53,6 +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;
alpha2 = globals->alpha * globals->alpha;
@@ -88,11 +89,10 @@
/*process candidate cells */
G_percent_reset();
- /* temperaral using 40x40 sub set for fast testing */
- for (row = globals->row_min; row < 40; row++) {
+ for (row = globals->row_min; row < globals->row_max; row++) {
G_percent(row - globals->row_min,
globals->row_max - globals->row_min, 4);
- for (col = globals->col_min; col < 40; col++) {
+ for (col = globals->col_min; col < globals->col_max; col++) {
if (!(FLAG_GET(globals->candidate_flag, row, col)))
continue;
/* left bound of the window */
@@ -118,13 +118,16 @@
window_col_east = globals->col_max;
}
/* calculate new band values */
- float sum_of_weights = 0;
- double new_val = 0;
-
+ 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));
+
/* 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++){
- float weight =1;
+ double weight[n_bands];
+ memset(weight,1,(n_bands)*sizeof(double));
/* 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)){
@@ -135,9 +138,12 @@
Segment_get(&globals->bands_seg, (void *)Rwin.mean,current_window_row, current_window_col);
/* check range bandwidth */
if ((globals->calculate_similarity)(&Rin, &Rwin, globals) <= (globals->ms_range_bandwidth * globals->ms_range_bandwidth)){
- weight *=gauss_kernel(pow((Rin.mean[0]-Rwin.mean[0]),2),distance2);
- sum_of_weights += weight;
- new_val += Rwin.mean[0]*weight;
+ 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];
+ } while(n--);
}
}
}/* end of moving window col */
@@ -145,10 +151,10 @@
/* write the output to bands_out*/
- Rout.mean[0] = new_val;
+ 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); */
- Segment_put(&globals->bands_seg, (void *)Rout.mean, row, col);
- /* G_message(_("test")); */
+
/* if the squared difference between old and new band values
* is larger than alpha2, then increase n_changes */
@@ -169,3 +175,15 @@
return TRUE;
}
+/* test out put the result */
+void print_matrix(struct globals *globals){
+ int i,j;
+ struct ngbr_stats R_prt;
+ R_prt.mean = G_malloc(globals->datasize);
+ 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);
+ }
+ }
+}
\ No newline at end of file
More information about the grass-commit
mailing list