-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmsegslow.cpp
3198 lines (2953 loc) · 162 KB
/
msegslow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* msegslow.cpp: MSEG Slow mode class *
* Version: 0.9.x *
* Last revised: 09/08/2009 *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* MSEG algorithm by Angelos Tzotsos ([email protected]) *
* Remote Sensing Lab NTUA - GCpp August 2009 *
* *
* Copyright (C) Angelos Tzotsos <[email protected]> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "msegslow.h"
int Slow_Mode::firstpass(Level& pass1, ERS_Image& Img, MSEG_Init& mseg, float level_ID, MSEG_Param& Param){
//cout << endl << "Inside first pass..." << endl;//Debug mode
int mergecounter = 0;
pass1.raster.reserve(Img.Lines*Img.Columns);
pass1.cycles = 1;
pass1.Lines = Img.Lines;
pass1.Columns = Img.Columns;
mseg.last_id = (Img.Lines*Img.Columns); //Set the first object id
//Let all the raster become -1
for (int i=0; i<(Img.Lines*Img.Columns); i++){
pass1.raster.push_back(-1); //Mporei na mn xreiazetai afou exoume kanei reserve
//pass1.raster[i] = -1;//Solution 2, without reallocating memory into the vector
}
//cout << "raster size = " << pass1.raster.size() << endl;//Debug mode
//Copy the id number
pass1.HierarchyID = level_ID;
//Copy segmentation parameters into new level
pass1.ScaleParameter = Param.Scale;
pass1.Color = Param.Color;
pass1.Compactness = Param.Compact;
pass1.Edge = Param.Edge;
pass1.Texture = Param.Texture;
//cout << "Parameters are: " << pass1.ScaleParameter << ", " << pass1.Color
//<< ", " << pass1.Compactness << endl;//Debug mode
//Declare a temporary object
Object tmp;
//cout << "Temp Object created" << endl;//Debug mode
//Generic Declarations
BoundaryLine tmpBoundaryLine;
//TopologyObject tmpTopologyObject;
PriorityObject tmp_priority_object;
pixel cur, up, down, right, left, best, best_up, best_down, best_right, best_left, best_best;
int cur_id, up_id, down_id, right_id, left_id, best_id, best_best_id;
int best_up_id, best_down_id, best_right_id, best_left_id;
int i, pri, sec, matches;
float best_h, up_h, down_h, left_h, right_h, best_up_h, best_down_h, best_right_h, best_left_h, best_best_h;
float std;
float cur_val, near_val;
//Check the SPE result number
if (mseg.StartingPoints.size() != Img.Macroblocks.size()){
cout << "Error in SPE result" << endl << "Quiting at first pass..." << endl;
exit(1);
}
int msize = Img.Macroblocks.size();
//For every macroblock
for(i=0;i<(Img.MacroLines * Img.MacroColumns);i++){
//Assume each pixel is an object and assign them false ids in order to use the priority_queue
//The pixel false id is the 1D [] representation inside the raster vector
//cout << "First pass completed: " << ((i+1)/msize)*100 << "%" << endl;//"/r";//Debug mode
pri = 1;//During first pass only primary is usefull.(inside macroblock)
sec = 1;
//Load the Starting Point
cur.line = mseg.StartingPoints[i].line;
cur.column = mseg.StartingPoints[i].column;
//cout << "Starting point: " << cur.line << "," << cur.column << endl;//Debug mode
cur_id = D1(Img.Lines, Img.Columns, cur.line, cur.column) + 1;
//cout << "Corresponding ID for starting point is: " << cur_id << endl;//Debug mode
//Check the boundary for the starting point
if ((cur.line<Img.Macroblocks[i].LineStart || cur.line>Img.Macroblocks[i].LineEnd)
||(cur.column<Img.Macroblocks[i].ColumnStart || cur.column>Img.Macroblocks[i].ColumnEnd)){
cout << "Starting point" << i << "out of bounds" << endl
<< "Quiting at first pass..." << endl;
exit(1);
}
//Push the first pixel to the priority_queue
tmp_priority_object.primary = pri;
tmp_priority_object.secondary = sec;
tmp_priority_object.id = cur_id;
//cout << "Priority object created with members:" << tmp_priority_object.primary
//<< " " << tmp_priority_object.secondary << " " << tmp_priority_object.id << endl;//Debug mode
mseg.PriorityList.push(tmp_priority_object);
pass1.raster[cur_id - 1] = 0; //Flag that it is loaded into priority list
//cout << "Priority object for macroblock created..." << endl;//Debug mode
//cout << "Priority list size at the begining is " << mseg.PriorityList.size() << endl;//Debug mode
//While the priority list is not empty
while (!mseg.PriorityList.empty()){
//cout << "Priority list currently holds " << mseg.PriorityList.size() << "id's"
//<< " and " << mergecounter << " merges have occured" << endl;//Debug mode
//Load the next priority object
tmp_priority_object = mseg.PriorityList.top();
pri = tmp_priority_object.primary;
sec = tmp_priority_object.secondary;
cur_id = tmp_priority_object.id;
//cout << "Top-ing object with id: " << cur_id << endl;//Debug mode
//cout << "Priority object loaded with members:" << tmp_priority_object.primary
//<< " " << tmp_priority_object.secondary << " " << tmp_priority_object.id << endl;//Debug mode
mseg.PriorityList.pop();//Perhaps to the end????
//If pixel has been merged...goto end of while loop
if(pass1.raster[cur_id - 1] > 0) continue;
//cout << "Pop-ing object" << endl;//Debug mode
//cout << "After pop, the priority list holds: " << mseg.PriorityList.size() << "objects" << endl;//Debug mode
cur = D2(cur_id, Img.Columns);
//cout << "made 2d transform" << endl;//Debug mode
//cout << "Current pixel's x,y is: " << cur.line << " " << cur.column << endl;//Debug mode
best_h = Param.Scale; //The maximum heterogeneity allowed is the scale parameter
matches = 0;
//Load neigbors
up.line = cur.line - 1;
up.column = cur.column;
up_id = (up.line >= 1) ? (D1(Img.Lines, Img.Columns, up.line, up.column) + 1) : 1;
down.line = cur.line + 1;
down.column = cur.column;
down_id = D1(Img.Lines, Img.Columns, down.line, down.column) + 1;
right.line = cur.line;
right.column = cur.column + 1;
right_id = D1(Img.Lines, Img.Columns, right.line, right.column) + 1;
left.line = cur.line;
left.column = cur.column - 1;
left_id = (left.column >= 1) ? (D1(Img.Lines, Img.Columns, left.line, left.column) + 1) : 1;
//cout << "loading neighbors..." << endl;//Debug mode
//Check neighbors
//TODO: Put everything into arrays and loop 4 times...
if((up.line>=Img.Macroblocks[i].LineStart && up.line<=Img.Macroblocks[i].LineEnd)
&& (up.column>=Img.Macroblocks[i].ColumnStart && up.column<=Img.Macroblocks[i].ColumnEnd)){
if(pass1.raster[up_id - 1] <= 0){
//Calculate heterogeneity
up_h = 0.0;
for (int b=1; b<=Img.Bands; b++){
cur_val = Img.Buffer(cur.line, cur.column, b);
near_val = Img.Buffer(up.line, up.column, b);
std = abs(cur_val - near_val)/2;
up_h += Img.BandWeight[b]* 2 * std;
}
//cout << "Heterogeneity calculated for up object " << up_h << endl;//Debug mode
//Is it a match? --> matches++ --> compare to best_h
if (up_h < Param.Scale){
matches++;
if (up_h < best_h){
best_h = up_h;
best_id = up_id;//We will copy the best outside this loop in order to spare copies
}
}
//cout << "Match compared" << endl;//Debug mode
//if raster value <0 --> push pixel in queue
if (pass1.raster[up_id - 1] == -1){
tmp_priority_object.primary = ++pri;//pri + 1
tmp_priority_object.secondary = sec;
tmp_priority_object.id = up_id;
//cout << "Priority object for up neighbor added with members: "
//<< tmp_priority_object.primary << " " << tmp_priority_object.secondary
//<< " " << tmp_priority_object.id << endl;//Debug mode
mseg.PriorityList.push(tmp_priority_object);
pass1.raster[up_id - 1] = 0;
//cout << "Neighbor pushed in priority list" << endl;//Debug mode
//cout << "Now priority list holds: " << mseg.PriorityList.size() << " objects" << endl;//Debug mode
}
}
}
if((down.line>=Img.Macroblocks[i].LineStart && down.line<=Img.Macroblocks[i].LineEnd)
&& (down.column>=Img.Macroblocks[i].ColumnStart && down.column<=Img.Macroblocks[i].ColumnEnd)){
if(pass1.raster[down_id - 1] <= 0){
//Calculate heterogeneity
down_h = 0.0;
for (int b=1; b<=Img.Bands; b++){
cur_val = Img.Buffer(cur.line, cur.column, b);
near_val = Img.Buffer(down.line, down.column, b);
std = abs(cur_val - near_val)/2;
down_h += Img.BandWeight[b]* 2 * std;
}
//cout << "Heterogeneity calculated for down object " << down_h << endl;//Debug mode
//Is it a match? --> matches++ --> compare to best_h
if (down_h < Param.Scale){
matches++;
if (down_h < best_h){
best_h = down_h;
best_id = down_id;//We will copy the best outside this loop in order to spare copies
}
}
//cout << "Match compared" << endl;//Debug mode
//if raster value <0 --> push pixel in queue
if (pass1.raster[down_id - 1] == -1){
tmp_priority_object.primary = ++pri;//+1;
tmp_priority_object.secondary = sec;
tmp_priority_object.id = down_id;
//cout << "Priority object for down neighbor added with members: "
//<< tmp_priority_object.primary << " " << tmp_priority_object.secondary
//<< " " << tmp_priority_object.id << endl;//Debug mode
mseg.PriorityList.push(tmp_priority_object);
pass1.raster[down_id - 1] = 0;
//cout << "Neighbor pushed in priority list" << endl;//Debug mode
//cout << "Now priority list holds: " << mseg.PriorityList.size() << " objects" << endl;//Debug mode
}
}
}
if((right.line>=Img.Macroblocks[i].LineStart && right.line<=Img.Macroblocks[i].LineEnd)
&& (right.column>=Img.Macroblocks[i].ColumnStart && right.column<=Img.Macroblocks[i].ColumnEnd)){
if(pass1.raster[right_id - 1] <= 0){
//Calculate heterogeneity
right_h = 0.0;
for (int b=1; b<=Img.Bands; b++){
cur_val = Img.Buffer(cur.line, cur.column, b);
near_val = Img.Buffer(right.line, right.column, b);
std = abs(cur_val - near_val)/2;
right_h += Img.BandWeight[b]* 2 * std;
}
//cout << "Heterogeneity calculated for right object " << right_h << endl;//Debug mode
//Is it a match? --> matches++ --> compare to best_h
if (right_h < Param.Scale){
matches++;
if (right_h < best_h){
best_h = right_h;
best_id = right_id;//We will copy the best outside this loop in order to spare copies
}
}
//cout << "Match compared" << endl;//Debug mode
//if raster value <0 --> push pixel in queue
if (pass1.raster[right_id - 1] == -1){
tmp_priority_object.primary = ++pri;//+1;
tmp_priority_object.secondary = sec;
tmp_priority_object.id = right_id;
//cout << "Priority object for right neighbor added with members: "
//<< tmp_priority_object.primary << " " << tmp_priority_object.secondary
//<< " " << tmp_priority_object.id << endl;//Debug mode
mseg.PriorityList.push(tmp_priority_object);
pass1.raster[right_id - 1] = 0;
//cout << "Neighbor pushed in priority list" << endl;//Debug mode
//cout << "Now priority list holds: " << mseg.PriorityList.size() << " objects" << endl;//Debug mode
}
}
}
if((left.line>=Img.Macroblocks[i].LineStart && left.line<=Img.Macroblocks[i].LineEnd)
&& (left.column>=Img.Macroblocks[i].ColumnStart && left.column<=Img.Macroblocks[i].ColumnEnd)){
if(pass1.raster[left_id - 1] <= 0){
//Calculate heterogeneity
left_h = 0.0;
for (int b=1; b<=Img.Bands; b++){
cur_val = Img.Buffer(cur.line, cur.column, b);
near_val = Img.Buffer(left.line, left.column, b);
std = abs(cur_val - near_val)/2;
left_h += Img.BandWeight[b]* 2 * std;
}
//cout << "Heterogeneity calculated for left object " << left_h << endl;//Debug mode
//Is it a match? --> matches++ --> compare to best_h
if (left_h < Param.Scale){
matches++;
if (left_h < best_h){
best_h = left_h;
best_id = left_id;//We will copy the best outside this loop in order to spare copies
}
}
//cout << "Match compared" << endl;//Debug mode
//if raster value <0 --> push pixel in queue
if (pass1.raster[left_id - 1] == -1){
tmp_priority_object.primary = pri+1;
tmp_priority_object.secondary = sec;
tmp_priority_object.id = left_id;
//cout << "Priority object for left neighbor added with members: "
//<< tmp_priority_object.primary << " " << tmp_priority_object.secondary
//<< " " << tmp_priority_object.id << endl;//Debug mode
mseg.PriorityList.push(tmp_priority_object);
pass1.raster[left_id - 1] = 0;
//cout << "Neighbor pushed in priority list" << endl;//Debug mode
//cout << "Now priority list holds: " << mseg.PriorityList.size() << " objects" << endl;//Debug mode
}
}
}
//Push it's neigbors into the priority list if they are not merged (done above)
//cout << "Done with neighbors..." << " Best match id is: " << best_id << endl;//Debug mode
//cout << "matches at this point are: " << matches << endl;//Debug mode
//Check for match
if(matches){
//Check for the best match
//cout << "Inside scope for best match..." << endl;//Debug mode
best = D2(best_id, Img.Columns);
//cout << "Best match x,y: " << best.line << " " << best.column << endl;//Debug mode
best_best_h = Param.Scale; //The maximum heterogeneity allowed is the scale parameter
//Load neigbors
best_up.line = best.line-1;
best_up.column = best.column;
best_up_id = (best_up.line >= 1) ? (D1(Img.Lines, Img.Columns, best_up.line, best_up.column) + 1) : 1;
best_down.line = best.line + 1;
best_down.column = best.column;
best_down_id = D1(Img.Lines, Img.Columns, best_down.line, best_down.column) + 1;
best_right.line = best.line;
best_right.column = best.column + 1;
best_right_id = D1(Img.Lines, Img.Columns, best_right.line, best_right.column) + 1;
best_left.line = best.line;
best_left.column = best.column -1;
best_left_id = (best_left.column >= 1) ? (D1(Img.Lines, Img.Columns, best_left.line, best_left.column) + 1) : 1;
//cout << "Neighbors loaded again..." << endl;//Debug mode
//Check neighbors
if((best_up.line>=Img.Macroblocks[i].LineStart && best_up.line<=Img.Macroblocks[i].LineEnd)
&& (best_up.column>=Img.Macroblocks[i].ColumnStart && best_up.column<=Img.Macroblocks[i].ColumnEnd)){
if(pass1.raster[best_up_id - 1] <= 0){
//Calculate heterogeneity
best_up_h = 0.0;
for (int b=1; b<=Img.Bands; b++){
cur_val = Img.Buffer(best.line, best.column, b);
near_val = Img.Buffer(best_up.line, best_up.column, b);
std = abs(cur_val - near_val)/2;
best_up_h += Img.BandWeight[b]* 2 * std;
}
//cout << "Inside best_up... Heterogeneity: " << best_up_h << endl;//Debug mode
//Is it a match? --> compare to best_h
if (best_up_h < best_best_h){
best_best_h = best_up_h;
best_best_id = best_up_id;//We will copy the best outside this loop in order to spare copies
}
//cout << "calculated best_up heterogeneity" << endl;//Debug mode
//if raster value <0 --> push pixel in queue
if (pass1.raster[best_up_id - 1] == -1){
tmp_priority_object.primary = ++pri;//pri + 1
tmp_priority_object.secondary = sec;
tmp_priority_object.id = best_up_id;
//cout << "Priority object for up neighbor added with members: "
//<< tmp_priority_object.primary << " " << tmp_priority_object.secondary
//<< " " << tmp_priority_object.id << endl;//Debug mode
mseg.PriorityList.push(tmp_priority_object);
pass1.raster[best_up_id - 1] = 0;
//cout << "Neighbor pushed in priority list" << endl;//Debug mode
//cout << "Now priority list holds: " << mseg.PriorityList.size() << " objects" << endl;//Debug mode
}
}
}
if((best_down.line>=Img.Macroblocks[i].LineStart && best_down.line<=Img.Macroblocks[i].LineEnd)
&& (best_down.column>=Img.Macroblocks[i].ColumnStart && best_down.column<=Img.Macroblocks[i].ColumnEnd)){
if(pass1.raster[best_down_id - 1] <= 0){
//Calculate heterogeneity
best_down_h = 0.0;
for (int b=1; b<=Img.Bands; b++){
cur_val = Img.Buffer(best.line, best.column, b);
near_val = Img.Buffer(best_down.line, best_down.column, b);
std = abs(cur_val - near_val)/2;
best_down_h += Img.BandWeight[b]* 2 * std;
}
//cout << "Inside best_down... Heterogeneity: " << best_down_h << endl;//Debug mode
//Is it a match? --> compare to best_h
if (best_down_h < best_best_h){
best_best_h = best_down_h;
best_best_id = best_down_id;//We will copy the best outside this loop in order to spare copies
}
//cout << "calculated best_down heterogeneity" << endl;//Debug mode
//if raster value <0 --> push pixel in queue
if (pass1.raster[best_down_id - 1] == -1){
tmp_priority_object.primary = ++pri;//pri + 1
tmp_priority_object.secondary = sec;
tmp_priority_object.id = best_down_id;
//cout << "Priority object for down neighbor added with members: "
//<< tmp_priority_object.primary << " " << tmp_priority_object.secondary
//<< " " << tmp_priority_object.id << endl;//Debug mode
mseg.PriorityList.push(tmp_priority_object);
pass1.raster[best_down_id - 1] = 0;
//cout << "Neighbor pushed in priority list" << endl;//Debug mode
//cout << "Now priority list holds: " << mseg.PriorityList.size() << " objects" << endl;//Debug mode
}
}
}
if((best_right.line>=Img.Macroblocks[i].LineStart && best_right.line<=Img.Macroblocks[i].LineEnd)
&& (best_right.column>=Img.Macroblocks[i].ColumnStart && best_right.column<=Img.Macroblocks[i].ColumnEnd)){
if(pass1.raster[best_right_id - 1] <= 0){
//Calculate heterogeneity
best_right_h = 0.0;
for (int b=1; b<=Img.Bands; b++){
cur_val = Img.Buffer(best.line, best.column, b);
near_val = Img.Buffer(best_right.line, best_right.column, b);
std = abs(cur_val - near_val)/2;
best_right_h += Img.BandWeight[b]* 2 * std;
}
//cout << "Inside best_right... Heterogeneity: " << best_right_h << endl;//Debug mode
//Is it a match? --> compare to best_h
if (best_right_h < best_best_h){
best_best_h = best_right_h;
best_best_id = best_right_id;//We will copy the best outside this loop in order to spare copies
}
//cout << "calculated best_right heterogeneity" << endl;//Debug mode
//if raster value <0 --> push pixel in queue
if (pass1.raster[best_right_id - 1] == -1){
tmp_priority_object.primary = ++pri;//pri + 1
tmp_priority_object.secondary = sec;
tmp_priority_object.id = best_right_id;
//cout << "Priority object for right neighbor added with members: "
//<< tmp_priority_object.primary << " " << tmp_priority_object.secondary
//<< " " << tmp_priority_object.id << endl;//Debug mode
mseg.PriorityList.push(tmp_priority_object);
pass1.raster[best_right_id - 1] = 0;
//cout << "Neighbor pushed in priority list" << endl;//Debug mode
//cout << "Now priority list holds: " << mseg.PriorityList.size() << " objects" << endl;//Debug mode
}
}
}
if((best_left.line>=Img.Macroblocks[i].LineStart && best_left.line<=Img.Macroblocks[i].LineEnd)
&& (best_left.column>=Img.Macroblocks[i].ColumnStart && best_left.column<=Img.Macroblocks[i].ColumnEnd)){
if(pass1.raster[best_left_id - 1] <= 0){
//Calculate heterogeneity
best_left_h = 0.0;
for (int b=1; b<=Img.Bands; b++){
cur_val = Img.Buffer(best.line, best.column, b);
near_val = Img.Buffer(best_left.line, best_left.column, b);
std = abs(cur_val - near_val)/2;
best_left_h += Img.BandWeight[b]* 2 * std;
}
//cout << "Inside best_left... Heterogeneity: " << best_left_h << endl;//Debug mode
//Is it a match? --> compare to best_h
if (best_left_h < best_best_h){
best_best_h = best_left_h;
best_best_id = best_left_id;//We will copy the best outside this loop in order to spare copies
}
//cout << "calculated best_left heterogeneity" << endl;//Debug mode
//if raster value <0 --> push pixel in queue
if (pass1.raster[best_left_id - 1] == -1){
tmp_priority_object.primary = ++pri;//pri + 1
tmp_priority_object.secondary = sec;
tmp_priority_object.id = best_left_id;
//cout << "Priority object for left neighbor added with members: "
//<< tmp_priority_object.primary << " " << tmp_priority_object.secondary
//<< " " << tmp_priority_object.id << endl;//Debug mode
mseg.PriorityList.push(tmp_priority_object);
pass1.raster[best_left_id - 1] = 0;
//cout << "Neighbor pushed in priority list" << endl;//Debug mode
//cout << "Now priority list holds: " << mseg.PriorityList.size() << " objects" << endl;//Debug mode
}
}
}
//Return best best match --> DONE(best_best_id)
//Is it mutual best match??
if(cur_id == best_best_id){
//If yes create object, return value --> Update raster, clear temp object
//cout << "Inside mutual best match..." << endl;//Debug mode
mseg.last_id++;//add 1 to last id to use to the current object
tmp.id = mseg.last_id;
tmp.area = 2;
mergecounter++;
//tmp.cycle = 1;
// Added for 0.7.0
for (int b=1; b<=Img.Bands; b++){
cur_val = Img.Buffer(cur.line, cur.column, b);
near_val = Img.Buffer(best.line, best.column, b);
tmp.Sum.push_back((cur_val+near_val));
tmp.SumSq.push_back((cur_val*cur_val)+(near_val*near_val));
}
if(cur.line == best.line){//the object will have one BoundaryLine object
tmpBoundaryLine.Line = cur.line;
if(cur.column<best.column){
tmpBoundaryLine.ColumnStart = cur.column;
tmpBoundaryLine.ColumnEnd = best.column;
}
else{
tmpBoundaryLine.ColumnStart = best.column;
tmpBoundaryLine.ColumnEnd = cur.column;
}
tmp.Boundary.push_back(tmpBoundaryLine);
}
else if(cur.line < best.line){//the object will have two BoundaryLine objects
tmpBoundaryLine.Line = cur.line;
tmpBoundaryLine.ColumnStart = cur.column;
tmpBoundaryLine.ColumnEnd = cur.column;
tmp.Boundary.push_back(tmpBoundaryLine);
tmpBoundaryLine.Line = best.line;
tmpBoundaryLine.ColumnStart = best.column;
tmpBoundaryLine.ColumnEnd = best.column;
tmp.Boundary.push_back(tmpBoundaryLine);
}
else {
tmpBoundaryLine.Line = best.line;
tmpBoundaryLine.ColumnStart = best.column;
tmpBoundaryLine.ColumnEnd = best.column;
tmp.Boundary.push_back(tmpBoundaryLine);
tmpBoundaryLine.Line = cur.line;
tmpBoundaryLine.ColumnStart = cur.column;
tmpBoundaryLine.ColumnEnd = cur.column;
tmp.Boundary.push_back(tmpBoundaryLine);
}
pass1.Objects.insert(make_pair(tmp.id, tmp));//insert will work better here...
//cout << "Object created succesfully..." << endl;//Debug mode
//tmpTopologyObject.id = tmp.id;
//tmpTopologyObject.merged = FALSE;
//tmpTopologyObject.new_id = 0;
//mseg.Topology.insert(make_pair(tmp.id, tmpTopologyObject));//insert here to
//cout << "Topology objects created..." << endl;//Debug mode
pass1.raster[cur_id - 1] = tmp.id;
pass1.raster[best_id - 1] = tmp.id;
tmp.clear();
//cout << "Temp Object cleared..." << endl;//Debug mode
}
else{
//If no mutual best match, push back in queue in priority +10 and move to next
//cout << "No mutual best match found, pushing back for later..." << endl;//Debug mode
tmp_priority_object.primary = pri+20;
tmp_priority_object.secondary = sec;
tmp_priority_object.id = cur_id;
mseg.PriorityList.push(tmp_priority_object);
}
}
else{//if cur has no matches
//cout << "No matches found, creating one pixel object..." << endl;//Debug mode
//create single pixel object --> Update raster, clear temp object
tmp.id = cur_id;
tmp.area = 1;
//tmp.cycle = 1;
// Added for 0.7.0
for (int b=1; b<=Img.Bands; b++){
cur_val = Img.Buffer(cur.line, cur.column, b);
tmp.Sum.push_back(cur_val);
tmp.SumSq.push_back((cur_val*cur_val));
}
tmpBoundaryLine.Line = cur.line;
tmpBoundaryLine.ColumnStart = cur.column;
tmpBoundaryLine.ColumnEnd = cur.column;
tmp.Boundary.push_back(tmpBoundaryLine);
pass1.Objects.insert(make_pair(tmp.id, tmp));//insert here to
//tmpTopologyObject.id = tmp.id;
//tmpTopologyObject.merged = FALSE;
//tmpTopologyObject.new_id = 0;
//mseg.Topology.insert(make_pair(tmp.id, tmpTopologyObject));//insert here to
pass1.raster[cur_id - 1] = cur_id;
tmp.clear();
}
}
//TODO:Check if some pixels have not been treated and create single pixel objects --> Update raster
}
//Create topology --> Load Topology
cout << endl << "Calculating overall topology now..." << endl;
Neighbor n;
n.merging_heterogeneity = 0.0;
for(int row=1; row<=Img.Lines; row++){
for(int col=1; col<=Img.Columns; col++){
cur.line = row;
cur.column = col;
up.line = cur.line-1;
up.column = cur.column;
down.line = cur.line + 1;
down.column = down.column;
right.line = cur.line;
right.column = cur.column + 1;
left.line = cur.line;
left.column = cur.column -1;
cur_id = pass1.raster[D1(Img.Lines, Img.Columns, cur.line, cur.column)];
if ((up.line>0 && up.line<=Img.Lines) && (up.column>0 && up.column<=Img.Columns)){
up_id = pass1.raster[D1(Img.Lines, Img.Columns, up.line, up.column)];
if(cur_id != up_id){
n.id = up_id;
if(pass1.Objects[cur_id].check_neighbor(up_id) == FALSE){
pass1.Objects[cur_id].Neighbors.push_back(n);
}
}
}
if ((down.line>0 && down.line<=Img.Lines) && (down.column>0 && down.column<=Img.Columns)){
down_id = pass1.raster[D1(Img.Lines, Img.Columns, down.line, down.column)];
if(cur_id != down_id){
n.id = down_id;
if(pass1.Objects[cur_id].check_neighbor(down_id) == FALSE){//Maybe disable and use fix() for speed...???
pass1.Objects[cur_id].Neighbors.push_back(n);
}
}
}
if ((right.line>0 && right.line<=Img.Lines) && (right.column>0 && right.column<=Img.Columns)){
right_id = pass1.raster[D1(Img.Lines, Img.Columns, right.line, right.column)];
if(cur_id != right_id){
n.id = right_id;
if(pass1.Objects[cur_id].check_neighbor(right_id) == FALSE){
pass1.Objects[cur_id].Neighbors.push_back(n);
}
}
}
if ((left.line>0 && left.line<=Img.Lines) && (left.column>0 && left.column<=Img.Columns)){
left_id = pass1.raster[D1(Img.Lines, Img.Columns, left.line, left.column)];
if(cur_id != left_id){
n.id = left_id;
if(pass1.Objects[cur_id].check_neighbor(left_id) == FALSE){
pass1.Objects[cur_id].Neighbors.push_back(n);
}
}
}
}
}
cout << "First pass completed succesfully!" << endl;
cout << "Objects allocated in first pass Level: " << pass1.Objects.size() << endl;
return mergecounter;
}
int Slow_Mode::firstpass(Level& pass1, ERS_Image& Img, MSEG_Init& mseg, float level_ID, MSEG_Param& Param, Level& super_level){
//cout << endl << "Inside first pass..." << endl;//Debug mode
int mergecounter = 0;
pass1.raster.reserve(Img.Lines*Img.Columns);
pass1.cycles = 1;
pass1.Lines = Img.Lines;
pass1.Columns = Img.Columns;
mseg.last_id = (Img.Lines*Img.Columns); //Set the first object id
//Let all the raster become -1
for (int i=0; i<(Img.Lines*Img.Columns); i++){
pass1.raster.push_back(-1); //Mporei na mn xreiazetai afou exoume kanei reserve
//pass1.raster[i] = -1;//Solution 2, without reallocating memory into the vector
}
//cout << "raster size = " << pass1.raster.size() << endl;//Debug mode
//Copy the id number
pass1.HierarchyID = level_ID;
//Copy segmentation parameters into new level
pass1.ScaleParameter = Param.Scale;
pass1.Color = Param.Color;
pass1.Compactness = Param.Compact;
pass1.Edge = Param.Edge;
pass1.Texture = Param.Texture;
//cout << "Parameters are: " << pass1.ScaleParameter << ", " << pass1.Color
//<< ", " << pass1.Compactness << endl;//Debug mode
//Declare a temporary object
Object tmp;
//cout << "Temp Object created" << endl;//Debug mode
//Generic Declarations
BoundaryLine tmpBoundaryLine;
//TopologyObject tmpTopologyObject;
PriorityObject tmp_priority_object;
pixel cur, up, down, right, left, best, best_up, best_down, best_right, best_left, best_best;
int cur_id, up_id, down_id, right_id, left_id, best_id, best_best_id;
int best_up_id, best_down_id, best_right_id, best_left_id;
int i, pri, sec, matches;
float best_h, up_h, down_h, left_h, right_h, best_up_h, best_down_h, best_right_h, best_left_h, best_best_h;
float std;
float cur_val, near_val;
//Check the SPE result number
if (mseg.StartingPoints.size() != Img.Macroblocks.size()){
cout << "Error in SPE result" << endl << "Quiting at first pass..." << endl;
exit(1);
}
int msize = Img.Macroblocks.size();
//For every macroblock
for(i=0;i<(Img.MacroLines * Img.MacroColumns);i++){
//Assume each pixel is an object and assign them false ids in order to use the priority_queue
//The pixel false id is the 1D [] representation inside the raster vector
//cout << "First pass completed: " << ((i+1)/msize)*100 << "%" << endl;//"/r";//Debug mode
pri = 1;//During first pass only primary is usefull.(inside macroblock)
sec = 1;
//Load the Starting Point
cur.line = mseg.StartingPoints[i].line;
cur.column = mseg.StartingPoints[i].column;
//cout << "Starting point: " << cur.line << "," << cur.column << endl;//Debug mode
cur_id = D1(Img.Lines, Img.Columns, cur.line, cur.column) + 1;
//cout << "Corresponding ID for starting point is: " << cur_id << endl;//Debug mode
//Check the boundary for the starting point
if ((cur.line<Img.Macroblocks[i].LineStart || cur.line>Img.Macroblocks[i].LineEnd)
||(cur.column<Img.Macroblocks[i].ColumnStart || cur.column>Img.Macroblocks[i].ColumnEnd)){
cout << "Starting point" << i << "out of bounds" << endl
<< "Quiting at first pass..." << endl;
exit(1);
}
//Push the first pixel to the priority_queue
tmp_priority_object.primary = pri;
tmp_priority_object.secondary = sec;
tmp_priority_object.id = cur_id;
//cout << "Priority object created with members:" << tmp_priority_object.primary
//<< " " << tmp_priority_object.secondary << " " << tmp_priority_object.id << endl;//Debug mode
mseg.PriorityList.push(tmp_priority_object);
pass1.raster[cur_id - 1] = 0; //Flag that it is loaded into priority list
//cout << "Priority object for macroblock created..." << endl;//Debug mode
//cout << "Priority list size at the begining is " << mseg.PriorityList.size() << endl;//Debug mode
//While the priority list is not empty
while (!mseg.PriorityList.empty()){
//cout << "Priority list currently holds " << mseg.PriorityList.size() << "id's"
//<< " and " << mergecounter << " merges have occured" << endl;//Debug mode
//Load the next priority object
tmp_priority_object = mseg.PriorityList.top();
pri = tmp_priority_object.primary;
sec = tmp_priority_object.secondary;
cur_id = tmp_priority_object.id;
//cout << "Top-ing object with id: " << cur_id << endl;//Debug mode
//cout << "Priority object loaded with members:" << tmp_priority_object.primary
//<< " " << tmp_priority_object.secondary << " " << tmp_priority_object.id << endl;//Debug mode
mseg.PriorityList.pop();//Perhaps to the end????
//If pixel has been merged...goto end of while loop
if(pass1.raster[cur_id - 1] > 0) continue;
//cout << "Pop-ing object" << endl;//Debug mode
//cout << "After pop, the priority list holds: " << mseg.PriorityList.size() << "objects" << endl;//Debug mode
cur = D2(cur_id, Img.Columns);
//cout << "made 2d transform" << endl;//Debug mode
//cout << "Current pixel's x,y is: " << cur.line << " " << cur.column << endl;//Debug mode
best_h = Param.Scale; //The maximum heterogeneity allowed is the scale parameter
matches = 0;
//Load neigbors
up.line = cur.line - 1;
up.column = cur.column;
up_id = (up.line >= 1) ? (D1(Img.Lines, Img.Columns, up.line, up.column) + 1) : 1;
down.line = cur.line + 1;
down.column = cur.column;
down_id = D1(Img.Lines, Img.Columns, down.line, down.column) + 1;
right.line = cur.line;
right.column = cur.column + 1;
right_id = D1(Img.Lines, Img.Columns, right.line, right.column) + 1;
left.line = cur.line;
left.column = cur.column - 1;
left_id = (left.column >= 1) ? (D1(Img.Lines, Img.Columns, left.line, left.column) + 1) : 1;
//cout << "loading neighbors..." << endl;//Debug mode
//Check neighbors
//TODO: Put everything into arrays and loop 4 times...
if((up.line>=Img.Macroblocks[i].LineStart && up.line<=Img.Macroblocks[i].LineEnd)
&& (up.column>=Img.Macroblocks[i].ColumnStart && up.column<=Img.Macroblocks[i].ColumnEnd)){
if(pass1.raster[up_id - 1] <= 0){
if(super_level.raster[up_id-1]==super_level.raster[cur_id-1]){
//Calculate heterogeneity
up_h = 0.0;
for (int b=1; b<=Img.Bands; b++){
cur_val = Img.Buffer(cur.line, cur.column, b);
near_val = Img.Buffer(up.line, up.column, b);
std = abs(cur_val - near_val)/2;
up_h += Img.BandWeight[b]* 2 * std;
}
//cout << "Heterogeneity calculated for up object " << up_h << endl;//Debug mode
//Is it a match? --> matches++ --> compare to best_h
if (up_h < Param.Scale){
matches++;
if (up_h < best_h){
best_h = up_h;
best_id = up_id;//We will copy the best outside this loop in order to spare copies
}
}
}
//cout << "Match compared" << endl;//Debug mode
//if raster value <0 --> push pixel in queue
if (pass1.raster[up_id - 1] == -1){
tmp_priority_object.primary = ++pri;//pri + 1
tmp_priority_object.secondary = sec;
tmp_priority_object.id = up_id;
//cout << "Priority object for up neighbor added with members: "
//<< tmp_priority_object.primary << " " << tmp_priority_object.secondary
//<< " " << tmp_priority_object.id << endl;//Debug mode
mseg.PriorityList.push(tmp_priority_object);
pass1.raster[up_id - 1] = 0;
//cout << "Neighbor pushed in priority list" << endl;//Debug mode
//cout << "Now priority list holds: " << mseg.PriorityList.size() << " objects" << endl;//Debug mode
}
}
}
if((down.line>=Img.Macroblocks[i].LineStart && down.line<=Img.Macroblocks[i].LineEnd)
&& (down.column>=Img.Macroblocks[i].ColumnStart && down.column<=Img.Macroblocks[i].ColumnEnd)){
if(pass1.raster[down_id - 1] <= 0){
if(super_level.raster[down_id-1]==super_level.raster[cur_id-1]){
//Calculate heterogeneity
down_h = 0.0;
for (int b=1; b<=Img.Bands; b++){
cur_val = Img.Buffer(cur.line, cur.column, b);
near_val = Img.Buffer(down.line, down.column, b);
std = abs(cur_val - near_val)/2;
down_h += Img.BandWeight[b]* 2 * std;
}
//cout << "Heterogeneity calculated for down object " << down_h << endl;//Debug mode
//Is it a match? --> matches++ --> compare to best_h
if (down_h < Param.Scale){
matches++;
if (down_h < best_h){
best_h = down_h;
best_id = down_id;//We will copy the best outside this loop in order to spare copies
}
}
}
//cout << "Match compared" << endl;//Debug mode
//if raster value <0 --> push pixel in queue
if (pass1.raster[down_id - 1] == -1){
tmp_priority_object.primary = ++pri;//+1;
tmp_priority_object.secondary = sec;
tmp_priority_object.id = down_id;
//cout << "Priority object for down neighbor added with members: "
//<< tmp_priority_object.primary << " " << tmp_priority_object.secondary
//<< " " << tmp_priority_object.id << endl;//Debug mode
mseg.PriorityList.push(tmp_priority_object);
pass1.raster[down_id - 1] = 0;
//cout << "Neighbor pushed in priority list" << endl;//Debug mode
//cout << "Now priority list holds: " << mseg.PriorityList.size() << " objects" << endl;//Debug mode
}
}
}
if((right.line>=Img.Macroblocks[i].LineStart && right.line<=Img.Macroblocks[i].LineEnd)
&& (right.column>=Img.Macroblocks[i].ColumnStart && right.column<=Img.Macroblocks[i].ColumnEnd)){
if(pass1.raster[right_id - 1] <= 0){
if(super_level.raster[right_id-1]==super_level.raster[cur_id-1]){
//Calculate heterogeneity
right_h = 0.0;
for (int b=1; b<=Img.Bands; b++){
cur_val = Img.Buffer(cur.line, cur.column, b);
near_val = Img.Buffer(right.line, right.column, b);
std = abs(cur_val - near_val)/2;
right_h += Img.BandWeight[b]* 2 * std;
}
//cout << "Heterogeneity calculated for right object " << right_h << endl;//Debug mode
//Is it a match? --> matches++ --> compare to best_h
if (right_h < Param.Scale){
matches++;
if (right_h < best_h){
best_h = right_h;
best_id = right_id;//We will copy the best outside this loop in order to spare copies
}
}
}
//cout << "Match compared" << endl;//Debug mode
//if raster value <0 --> push pixel in queue
if (pass1.raster[right_id - 1] == -1){
tmp_priority_object.primary = ++pri;//+1;
tmp_priority_object.secondary = sec;
tmp_priority_object.id = right_id;
//cout << "Priority object for right neighbor added with members: "
//<< tmp_priority_object.primary << " " << tmp_priority_object.secondary
//<< " " << tmp_priority_object.id << endl;//Debug mode
mseg.PriorityList.push(tmp_priority_object);
pass1.raster[right_id - 1] = 0;
//cout << "Neighbor pushed in priority list" << endl;//Debug mode
//cout << "Now priority list holds: " << mseg.PriorityList.size() << " objects" << endl;//Debug mode
}
}
}
if((left.line>=Img.Macroblocks[i].LineStart && left.line<=Img.Macroblocks[i].LineEnd)
&& (left.column>=Img.Macroblocks[i].ColumnStart && left.column<=Img.Macroblocks[i].ColumnEnd)){
if(pass1.raster[left_id - 1] <= 0){
if(super_level.raster[left_id-1]==super_level.raster[cur_id-1]){
//Calculate heterogeneity
left_h = 0.0;
for (int b=1; b<=Img.Bands; b++){
cur_val = Img.Buffer(cur.line, cur.column, b);
near_val = Img.Buffer(left.line, left.column, b);
std = abs(cur_val - near_val)/2;
left_h += Img.BandWeight[b]* 2 * std;
}
//cout << "Heterogeneity calculated for left object " << left_h << endl;//Debug mode
//Is it a match? --> matches++ --> compare to best_h
if (left_h < Param.Scale){
matches++;
if (left_h < best_h){
best_h = left_h;
best_id = left_id;//We will copy the best outside this loop in order to spare copies
}
}
}
//cout << "Match compared" << endl;//Debug mode
//if raster value <0 --> push pixel in queue
if (pass1.raster[left_id - 1] == -1){
tmp_priority_object.primary = pri+1;
tmp_priority_object.secondary = sec;
tmp_priority_object.id = left_id;
//cout << "Priority object for left neighbor added with members: "
//<< tmp_priority_object.primary << " " << tmp_priority_object.secondary
//<< " " << tmp_priority_object.id << endl;//Debug mode
mseg.PriorityList.push(tmp_priority_object);
pass1.raster[left_id - 1] = 0;
//cout << "Neighbor pushed in priority list" << endl;//Debug mode
//cout << "Now priority list holds: " << mseg.PriorityList.size() << " objects" << endl;//Debug mode
}
}
}
//Push it's neigbors into the priority list if they are not merged (done above)
//cout << "Done with neighbors..." << " Best match id is: " << best_id << endl;//Debug mode
//cout << "matches at this point are: " << matches << endl;//Debug mode
//Check for match
if(matches){
//Check for the best match
//cout << "Inside scope for best match..." << endl;//Debug mode
best = D2(best_id, Img.Columns);
//cout << "Best match x,y: " << best.line << " " << best.column << endl;//Debug mode
best_best_h = Param.Scale; //The maximum heterogeneity allowed is the scale parameter
//Load neigbors
best_up.line = best.line-1;
best_up.column = best.column;
best_up_id = (best_up.line >= 1) ? (D1(Img.Lines, Img.Columns, best_up.line, best_up.column) + 1) : 1;
best_down.line = best.line + 1;
best_down.column = best.column;
best_down_id = D1(Img.Lines, Img.Columns, best_down.line, best_down.column) + 1;
best_right.line = best.line;
best_right.column = best.column + 1;
best_right_id = D1(Img.Lines, Img.Columns, best_right.line, best_right.column) + 1;
best_left.line = best.line;
best_left.column = best.column -1;
best_left_id = (best_left.column >= 1) ? (D1(Img.Lines, Img.Columns, best_left.line, best_left.column) + 1) : 1;
//cout << "Neighbors loaded again..." << endl;//Debug mode
//Check neighbors
if((best_up.line>=Img.Macroblocks[i].LineStart && best_up.line<=Img.Macroblocks[i].LineEnd)
&& (best_up.column>=Img.Macroblocks[i].ColumnStart && best_up.column<=Img.Macroblocks[i].ColumnEnd)){
if(pass1.raster[best_up_id - 1] <= 0){
if(super_level.raster[best_up_id-1]==super_level.raster[best_id-1]){
//Calculate heterogeneity
best_up_h = 0.0;
for (int b=1; b<=Img.Bands; b++){
cur_val = Img.Buffer(best.line, best.column, b);
near_val = Img.Buffer(best_up.line, best_up.column, b);
std = abs(cur_val - near_val)/2;
best_up_h += Img.BandWeight[b]* 2 * std;
}
//cout << "Inside best_up... Heterogeneity: " << best_up_h << endl;//Debug mode
//Is it a match? --> compare to best_h
if (best_up_h < best_best_h){
best_best_h = best_up_h;
best_best_id = best_up_id;//We will copy the best outside this loop in order to spare copies
}
}
//cout << "calculated best_up heterogeneity" << endl;//Debug mode
//if raster value <0 --> push pixel in queue
if (pass1.raster[best_up_id - 1] == -1){
tmp_priority_object.primary = ++pri;//pri + 1
tmp_priority_object.secondary = sec;
tmp_priority_object.id = best_up_id;
//cout << "Priority object for up neighbor added with members: "
//<< tmp_priority_object.primary << " " << tmp_priority_object.secondary
//<< " " << tmp_priority_object.id << endl;//Debug mode
mseg.PriorityList.push(tmp_priority_object);
pass1.raster[best_up_id - 1] = 0;
//cout << "Neighbor pushed in priority list" << endl;//Debug mode
//cout << "Now priority list holds: " << mseg.PriorityList.size() << " objects" << endl;//Debug mode
}
}
}
if((best_down.line>=Img.Macroblocks[i].LineStart && best_down.line<=Img.Macroblocks[i].LineEnd)
&& (best_down.column>=Img.Macroblocks[i].ColumnStart && best_down.column<=Img.Macroblocks[i].ColumnEnd)){
if(pass1.raster[best_down_id - 1] <= 0){
if(super_level.raster[best_down_id-1]==super_level.raster[best_id-1]){
//Calculate heterogeneity
best_down_h = 0.0;
for (int b=1; b<=Img.Bands; b++){