@@ -246,6 +246,9 @@ char *cmdline2, cwd[2000];
246
246
char *rusage_file=NULL ;
247
247
char *PreGibbsFile=NULL ;
248
248
int n_omp_threads;
249
+ MRI *InsertFromSeg=NULL ;
250
+ std::vector<int > InsertFromSegIndices;
251
+ int MRIinsertFromSeg (MRI *mri_labeled, MRI *InsertFromSeg, std::vector<int > InsertFromSegIndices);
249
252
250
253
int main (int argc, char *argv[])
251
254
{
@@ -1413,6 +1416,11 @@ int main(int argc, char *argv[])
1413
1416
mri_labeled = newseg;
1414
1417
}
1415
1418
1419
+ if (InsertFromSeg){
1420
+ printf (" Inserting from seg\n " );
1421
+ MRIinsertFromSeg (mri_labeled, InsertFromSeg, InsertFromSegIndices);
1422
+ }
1423
+
1416
1424
printf (" writing labeled volume to %s\n " , out_fname) ;
1417
1425
if (MRIwrite (mri_labeled, out_fname) != NO_ERROR)
1418
1426
{
@@ -1464,9 +1472,9 @@ int main(int argc, char *argv[])
1464
1472
seconds = nint ((float )msec/1000 .0f ) ;
1465
1473
minutes = seconds / 60 ;
1466
1474
seconds = seconds % 60 ;
1467
- printf (" auto-labeling took %d minutes and %d seconds.\n " ,
1468
- minutes, seconds) ;
1469
- return (0 ) ;
1475
+ printf (" mri_ca_label took %d minutes and %d seconds.\n " , minutes, seconds) ;
1476
+ printf ( " mri_ca_label done \n " ) ;
1477
+ exit (0 );
1470
1478
}
1471
1479
/* ----------------------------------------------------------------------
1472
1480
Parameters:
@@ -1546,6 +1554,43 @@ get_option(int argc, char *argv[])
1546
1554
nowmsa = 1 ;
1547
1555
printf (" disabling WMSA labels\n " ) ;
1548
1556
}
1557
+ else if (!stricmp (option, " insert-from-seg" ) || !stricmp (option, " sa-insert-from-seg" ))
1558
+ {
1559
+ // -insert-from-seg InserFromSeg.mgz index1 <index2 ...>
1560
+ // -sa-insert-from-seg InserFromSeg.mgz index1 <index2 ...> InputSeg OutputSeg
1561
+ InsertFromSeg = MRIread (argv[2 ]);
1562
+ if (!InsertFromSeg) exit (1 );
1563
+ printf (" Inserting from seg %s " ,argv[2 ]);
1564
+ nargs = 1 ;
1565
+ int k=3 ;
1566
+ while (1 ){
1567
+ if (!argv[k]) break ;
1568
+ if (!isdigit (argv[k][0 ])) break ;
1569
+ InsertFromSegIndices.push_back (atoi (argv[k]));
1570
+ printf (" %s " ,argv[k]);
1571
+ k++;
1572
+ nargs++;
1573
+ }
1574
+ printf (" \n " );
1575
+ if (InsertFromSegIndices.size ()==0 ) {
1576
+ printf (" ERROR: -insert-from-seg needs at least one index to insert\n " );
1577
+ exit (1 );
1578
+ }
1579
+ MRI *InputSeg=NULL ;
1580
+ if (!stricmp (option, " sa-insert-from-seg" )){
1581
+ if (argv[k]==NULL || argv[k+1 ]==NULL ){
1582
+ printf (" ERROR: -sa-insert-from-seg needs an input and output seg\n " );
1583
+ exit (1 );
1584
+ }
1585
+ InputSeg = MRIread (argv[k]);
1586
+ if (!InputSeg) exit (1 );
1587
+ printf (" Inserting from seg\n " );
1588
+ MRIinsertFromSeg (InputSeg, InsertFromSeg, InsertFromSegIndices);
1589
+ int err = MRIwrite (InputSeg,argv[k+1 ]);
1590
+ exit (err);
1591
+ }
1592
+ printf (" \n " ) ;
1593
+ }
1549
1594
else if (!stricmp (option, " insert-wm-bet-putctx" )){
1550
1595
sscanf (argv[2 ]," %d" ,&insert_wm_bet_putctx_topo);
1551
1596
nargs = 1 ;
@@ -5382,3 +5427,50 @@ MRI *insert_wm_bet_putctx(MRI *seg, int topo, const char *psfile, MRI *out)
5382
5427
fflush (stdout);
5383
5428
return (out);
5384
5429
}
5430
+
5431
+
5432
+ int MRIinsertFromSeg (MRI *mri_labeled, MRI *InsertFromSeg, std::vector<int > InsertFromSegIndices)
5433
+ {
5434
+ int nchanged=0 ;
5435
+ for (int c=0 ; c < mri_labeled->width ; c++){
5436
+ for (int r=0 ; r < mri_labeled->height ; r++){
5437
+ for (int s=0 ; s < mri_labeled->depth ; s++){
5438
+ // Get the indices of this voxel for both segs
5439
+ int i1 = MRIgetVoxVal (mri_labeled,c,r,s,0 );
5440
+ int i2 = MRIgetVoxVal (InsertFromSeg,c,r,s,0 );
5441
+
5442
+ if (i1 == i2) continue ; // both the same so keep as is
5443
+
5444
+ // Check whether i1, i2 are in the list
5445
+ int i1InList=0 , i2InList=0 ;
5446
+ for (int n=0 ; n < InsertFromSegIndices.size (); n++){
5447
+ if (i1==InsertFromSegIndices[n]){
5448
+ i1InList = 1 ;
5449
+ break ;
5450
+ }
5451
+ }
5452
+ for (int n=0 ; n < InsertFromSegIndices.size (); n++){
5453
+ if (i2==InsertFromSegIndices[n]){
5454
+ i2InList = 1 ;
5455
+ break ;
5456
+ }
5457
+ }
5458
+ // Neither are in the list, so keep as is
5459
+ if (!i1InList && !i2InList) continue ;
5460
+
5461
+ // At this point, at least one of them is in the list, so
5462
+ // replace it. This will change things on the boundary. Eg, if
5463
+ // i1 is cblum wm and i2 is brainstem, then i1 will become
5464
+ // brainstem eventhough brainstem is not in the list. This is
5465
+ // probably ok for the main application (replacing aseg cblum
5466
+ // with synthseg cblum), but I worry a little bit about causing
5467
+ // some artifacts near the boundaries.
5468
+ MRIsetVoxVal (mri_labeled,c,r,s,0 ,i2);
5469
+ nchanged++;
5470
+
5471
+ }
5472
+ }
5473
+ }
5474
+ printf (" MRIinsertFromSeg() changed %d\n " ,nchanged);
5475
+ return (nchanged);
5476
+ }
0 commit comments