Commit c41c4815f8f0e80e8d1c73df3c5579a4d8293529
1 parent
42876a25
Exists in
orientation
Taking account direction cosines and the signed distance to know if a sagital ca…
…se is stacked L->R or R->L
Showing
1 changed file
with
38 additions
and
6 deletions
Show diff stats
invesalius/data/imagedata_utils.py
| @@ -438,16 +438,48 @@ def get_stacking_direction(files, orientation): | @@ -438,16 +438,48 @@ def get_stacking_direction(files, orientation): | ||
| 438 | r2.Update() | 438 | r2.Update() |
| 439 | p2 = r2.GetImagePositionPatient() | 439 | p2 = r2.GetImagePositionPatient() |
| 440 | 440 | ||
| 441 | + dc = r1.GetMedicalImageProperties().GetDirectionCosine() | ||
| 442 | + dc1 = numpy.array(dc[:3]) | ||
| 443 | + dc2 = numpy.array(dc[3:]) | ||
| 444 | + dc3 = numpy.cross(dc1, dc2) | ||
| 445 | + | ||
| 446 | + distp = numpy.array(p2) - numpy.array(p1) | ||
| 447 | + ndistp = distp / numpy.linalg.norm(distp) | ||
| 448 | + distv = numpy.dot(dc3, ndistp) | ||
| 449 | + | ||
| 441 | if orientation == 'SAGITTAL': | 450 | if orientation == 'SAGITTAL': |
| 442 | - d = (p2[0] - p1[0]) | 451 | + |
| 452 | + if dc3[0] < 0: | ||
| 453 | + if distv > 0: | ||
| 454 | + dirx = -1 | ||
| 455 | + else: | ||
| 456 | + dirx = 1 | ||
| 457 | + else: | ||
| 458 | + if distv < 0: | ||
| 459 | + dirx = -1 | ||
| 460 | + else: | ||
| 461 | + dirx = 1 | ||
| 462 | + | ||
| 463 | + ds = [ dirx, | ||
| 464 | + -1 if dc1[1] < 0 else 1, | ||
| 465 | + -1 if dc2[2] < 0 else 1, | ||
| 466 | + ] | ||
| 443 | 467 | ||
| 444 | elif orientation == 'CORONAL': | 468 | elif orientation == 'CORONAL': |
| 445 | d = (p2[1] - p1[1]) | 469 | d = (p2[1] - p1[1]) |
| 470 | + d = int(d / abs(d)) | ||
| 471 | + ds = [] | ||
| 446 | 472 | ||
| 447 | else: | 473 | else: |
| 448 | d = (p2[2] - p1[2]) | 474 | d = (p2[2] - p1[2]) |
| 475 | + d = int(d / abs(d)) | ||
| 476 | + ds = [] | ||
| 477 | + | ||
| 478 | + print "===================================" | ||
| 479 | + print dc1, dc2, dc3, ds, p2, p1, p2, distv | ||
| 480 | + print "===================================" | ||
| 449 | 481 | ||
| 450 | - return int(d / abs(d)) | 482 | + return ds |
| 451 | 483 | ||
| 452 | 484 | ||
| 453 | def dcm2memmap(files, slice_size, orientation, resolution_percentage): | 485 | def dcm2memmap(files, slice_size, orientation, resolution_percentage): |
| @@ -514,14 +546,14 @@ def dcm2memmap(files, slice_size, orientation, resolution_percentage): | @@ -514,14 +546,14 @@ def dcm2memmap(files, slice_size, orientation, resolution_percentage): | ||
| 514 | elif orientation == 'SAGITTAL': | 546 | elif orientation == 'SAGITTAL': |
| 515 | array.shape = matrix.shape[0], matrix.shape[1] | 547 | array.shape = matrix.shape[0], matrix.shape[1] |
| 516 | 548 | ||
| 517 | - print ">>>", d, dcm_reader.GetImagePositionPatient(), dcm_reader.GetDirectionCosines() | 549 | + #print ">>>", d, dcm_reader.GetImagePositionPatient(), dcm_reader.GetMedicalImageProperties().GetDirectionCosine() |
| 518 | 550 | ||
| 519 | # stacking from right to left | 551 | # stacking from right to left |
| 520 | - if d == 1: | ||
| 521 | - matrix[:, :,n] = array[:, ::-1] | 552 | + if d[0] == 1: |
| 553 | + matrix[:, :, n] = array[::d[1], ::d[2]] | ||
| 522 | # stacking from left to right | 554 | # stacking from left to right |
| 523 | else: | 555 | else: |
| 524 | - matrix[:, :,-n-1] = array[:, ::-1] | 556 | + matrix[:, :, -n-1] = array[::d[1], ::d[2]] |
| 525 | else: | 557 | else: |
| 526 | print array.shape, matrix.shape | 558 | print array.shape, matrix.shape |
| 527 | array.shape = matrix.shape[1], matrix.shape[2] | 559 | array.shape = matrix.shape[1], matrix.shape[2] |