Commit dfdc8ce8be5b4be448b60123632889b77ee5dee0
1 parent
4209ef5f
Exists in
master
and in
56 other branches
Inverting direction of projection to mip
Showing
1 changed file
with
127 additions
and
147 deletions
Show diff stats
invesalius/data/slice_.py
| ... | ... | @@ -426,14 +426,14 @@ class Slice(object): |
| 426 | 426 | self.buffer_slices[orientation].discard_vtk_mask() |
| 427 | 427 | |
| 428 | 428 | |
| 429 | - def GetSlices(self, orientation, slice_number, number_slices): | |
| 429 | + def GetSlices(self, orientation, slice_number, number_slices, inverted=False): | |
| 430 | 430 | if self.buffer_slices[orientation].index == slice_number and \ |
| 431 | 431 | self._type_projection == const.PROJECTION_NORMAL: |
| 432 | 432 | if self.buffer_slices[orientation].vtk_image: |
| 433 | 433 | image = self.buffer_slices[orientation].vtk_image |
| 434 | 434 | else: |
| 435 | 435 | n_image = self.get_image_slice(orientation, slice_number, |
| 436 | - number_slices) | |
| 436 | + number_slices, inverted) | |
| 437 | 437 | image = converters.to_vtk(n_image, self.spacing, slice_number, orientation) |
| 438 | 438 | ww_wl_image = self.do_ww_wl(image) |
| 439 | 439 | image = self.do_colour_image(ww_wl_image) |
| ... | ... | @@ -454,7 +454,7 @@ class Slice(object): |
| 454 | 454 | self.buffer_slices[orientation].vtk_image = image |
| 455 | 455 | else: |
| 456 | 456 | n_image = self.get_image_slice(orientation, slice_number, |
| 457 | - number_slices) | |
| 457 | + number_slices, inverted) | |
| 458 | 458 | image = converters.to_vtk(n_image, self.spacing, slice_number, orientation) |
| 459 | 459 | ww_wl_image = self.do_ww_wl(image) |
| 460 | 460 | image = self.do_colour_image(ww_wl_image) |
| ... | ... | @@ -477,7 +477,7 @@ class Slice(object): |
| 477 | 477 | |
| 478 | 478 | return final_image |
| 479 | 479 | |
| 480 | - def get_image_slice(self, orientation, slice_number, number_slices=1): | |
| 480 | + def get_image_slice(self, orientation, slice_number, number_slices=1, inverted=False): | |
| 481 | 481 | if self.buffer_slices[orientation].index == slice_number \ |
| 482 | 482 | and self.buffer_slices[orientation].image is not None: |
| 483 | 483 | n_image = self.buffer_slices[orientation].image |
| ... | ... | @@ -486,161 +486,141 @@ class Slice(object): |
| 486 | 486 | if orientation == 'AXIAL': |
| 487 | 487 | if self._type_projection == const.PROJECTION_NORMAL: |
| 488 | 488 | n_image = numpy.array(self.matrix[slice_number]) |
| 489 | - elif self._type_projection == const.PROJECTION_MaxIP: | |
| 490 | - n_image = numpy.array(self.matrix[slice_number: | |
| 491 | - slice_number+number_slices]).max(0) | |
| 492 | - elif self._type_projection == const.PROJECTION_MinIP: | |
| 493 | - n_image = numpy.array(self.matrix[slice_number: | |
| 494 | - slice_number+number_slices]).min(0) | |
| 495 | - elif self._type_projection == const.PROJECTION_MeanIP: | |
| 496 | - n_image = numpy.array(self.matrix[slice_number: | |
| 497 | - slice_number+number_slices]).mean(0) | |
| 498 | - elif self._type_projection == const.PROJECTION_LMIP: | |
| 499 | - tmp_array = numpy.array(self.matrix[slice_number: | |
| 500 | - slice_number + number_slices]) | |
| 501 | - n_image = numpy.empty(shape=(tmp_array.shape[1], | |
| 502 | - tmp_array.shape[2]), | |
| 503 | - dtype=tmp_array.dtype) | |
| 504 | - mips.lmip(tmp_array, 0, self.window_level, self.window_level, n_image) | |
| 505 | - elif self._type_projection == const.PROJECTION_MIDA: | |
| 506 | - tmp_array = numpy.array(self.matrix[slice_number: | |
| 507 | - slice_number + number_slices]) | |
| 508 | - n_image = numpy.empty(shape=(tmp_array.shape[1], | |
| 509 | - tmp_array.shape[2]), | |
| 510 | - dtype=tmp_array.dtype) | |
| 511 | - mips.mida(tmp_array, 0, self.window_level, self.window_level, n_image) | |
| 512 | - elif self._type_projection == const.PROJECTION_CONTOUR_MIP: | |
| 513 | - tmp_array = numpy.array(self.matrix[slice_number: | |
| 514 | - slice_number + number_slices]) | |
| 515 | - n_image = numpy.empty(shape=(tmp_array.shape[1], | |
| 516 | - tmp_array.shape[2]), | |
| 517 | - dtype=tmp_array.dtype) | |
| 518 | - mips.fast_countour_mip(tmp_array, self.n_border, 0, self.window_level, | |
| 519 | - self.window_level, 0, n_image) | |
| 520 | - elif self._type_projection == const.PROJECTION_CONTOUR_LMIP: | |
| 521 | - tmp_array = numpy.array(self.matrix[slice_number: | |
| 522 | - slice_number + number_slices]) | |
| 523 | - n_image = numpy.empty(shape=(tmp_array.shape[1], | |
| 524 | - tmp_array.shape[2]), | |
| 525 | - dtype=tmp_array.dtype) | |
| 526 | - mips.fast_countour_mip(tmp_array, self.n_border, 0, self.window_level, | |
| 527 | - self.window_level, 1, n_image) | |
| 528 | - elif self._type_projection == const.PROJECTION_CONTOUR_MIDA: | |
| 489 | + else: | |
| 529 | 490 | tmp_array = numpy.array(self.matrix[slice_number: |
| 530 | 491 | slice_number + number_slices]) |
| 531 | - n_image = numpy.empty(shape=(tmp_array.shape[1], | |
| 532 | - tmp_array.shape[2]), | |
| 533 | - dtype=tmp_array.dtype) | |
| 534 | - mips.fast_countour_mip(tmp_array, self.n_border, 0, self.window_level, | |
| 535 | - self.window_level, 2, n_image) | |
| 536 | - else: | |
| 537 | - n_image = numpy.array(self.matrix[slice_number]) | |
| 492 | + if inverted: | |
| 493 | + tmp_array = tmp_array[::-1] | |
| 494 | + | |
| 495 | + if self._type_projection == const.PROJECTION_MaxIP: | |
| 496 | + n_image = numpy.array(tmp_array).max(0) | |
| 497 | + elif self._type_projection == const.PROJECTION_MinIP: | |
| 498 | + n_image = numpy.array(tmp_array).min(0) | |
| 499 | + elif self._type_projection == const.PROJECTION_MeanIP: | |
| 500 | + n_image = numpy.array(tmp_array).mean(0) | |
| 501 | + elif self._type_projection == const.PROJECTION_LMIP: | |
| 502 | + n_image = numpy.empty(shape=(tmp_array.shape[1], | |
| 503 | + tmp_array.shape[2]), | |
| 504 | + dtype=tmp_array.dtype) | |
| 505 | + mips.lmip(tmp_array, 0, self.window_level, self.window_level, n_image) | |
| 506 | + elif self._type_projection == const.PROJECTION_MIDA: | |
| 507 | + n_image = numpy.empty(shape=(tmp_array.shape[1], | |
| 508 | + tmp_array.shape[2]), | |
| 509 | + dtype=tmp_array.dtype) | |
| 510 | + mips.mida(tmp_array, 0, self.window_level, self.window_level, n_image) | |
| 511 | + elif self._type_projection == const.PROJECTION_CONTOUR_MIP: | |
| 512 | + n_image = numpy.empty(shape=(tmp_array.shape[1], | |
| 513 | + tmp_array.shape[2]), | |
| 514 | + dtype=tmp_array.dtype) | |
| 515 | + mips.fast_countour_mip(tmp_array, self.n_border, 0, self.window_level, | |
| 516 | + self.window_level, 0, n_image) | |
| 517 | + elif self._type_projection == const.PROJECTION_CONTOUR_LMIP: | |
| 518 | + n_image = numpy.empty(shape=(tmp_array.shape[1], | |
| 519 | + tmp_array.shape[2]), | |
| 520 | + dtype=tmp_array.dtype) | |
| 521 | + mips.fast_countour_mip(tmp_array, self.n_border, 0, self.window_level, | |
| 522 | + self.window_level, 1, n_image) | |
| 523 | + elif self._type_projection == const.PROJECTION_CONTOUR_MIDA: | |
| 524 | + n_image = numpy.empty(shape=(tmp_array.shape[1], | |
| 525 | + tmp_array.shape[2]), | |
| 526 | + dtype=tmp_array.dtype) | |
| 527 | + mips.fast_countour_mip(tmp_array, self.n_border, 0, self.window_level, | |
| 528 | + self.window_level, 2, n_image) | |
| 529 | + else: | |
| 530 | + n_image = numpy.array(self.matrix[slice_number]) | |
| 538 | 531 | |
| 539 | 532 | elif orientation == 'CORONAL': |
| 540 | 533 | if self._type_projection == const.PROJECTION_NORMAL: |
| 541 | 534 | n_image = numpy.array(self.matrix[..., slice_number, ...]) |
| 542 | - elif self._type_projection == const.PROJECTION_MaxIP: | |
| 543 | - n_image = numpy.array(self.matrix[..., slice_number: | |
| 544 | - slice_number+number_slices, ...]).max(1) | |
| 545 | - elif self._type_projection == const.PROJECTION_MinIP: | |
| 546 | - n_image = numpy.array(self.matrix[..., slice_number: | |
| 547 | - slice_number+number_slices, ...]).min(1) | |
| 548 | - elif self._type_projection == const.PROJECTION_MeanIP: | |
| 549 | - n_image = numpy.array(self.matrix[..., slice_number: | |
| 550 | - slice_number+number_slices, ...]).mean(1) | |
| 551 | - elif self._type_projection == const.PROJECTION_LMIP: | |
| 552 | - tmp_array = numpy.array(self.matrix[..., slice_number: | |
| 553 | - slice_number + number_slices, ...]) | |
| 554 | - n_image = numpy.empty(shape=(tmp_array.shape[0], | |
| 555 | - tmp_array.shape[2]), | |
| 556 | - dtype=tmp_array.dtype) | |
| 557 | - mips.lmip(tmp_array, 1, self.window_level, self.window_level, n_image) | |
| 558 | - elif self._type_projection == const.PROJECTION_MIDA: | |
| 559 | - tmp_array = numpy.array(self.matrix[..., slice_number: | |
| 560 | - slice_number + number_slices, ...]) | |
| 561 | - n_image = numpy.empty(shape=(tmp_array.shape[0], | |
| 562 | - tmp_array.shape[2]), | |
| 563 | - dtype=tmp_array.dtype) | |
| 564 | - mips.mida(tmp_array, 1, self.window_level, self.window_level, n_image) | |
| 565 | - elif self._type_projection == const.PROJECTION_CONTOUR_MIP: | |
| 566 | - tmp_array = numpy.array(self.matrix[..., slice_number: | |
| 567 | - slice_number + number_slices, ...]) | |
| 568 | - n_image = numpy.empty(shape=(tmp_array.shape[0], | |
| 569 | - tmp_array.shape[2]), | |
| 570 | - dtype=tmp_array.dtype) | |
| 571 | - mips.fast_countour_mip(tmp_array, self.n_border, 1, self.window_level, | |
| 572 | - self.window_level, 0, n_image) | |
| 573 | - elif self._type_projection == const.PROJECTION_CONTOUR_LMIP: | |
| 574 | - tmp_array = numpy.array(self.matrix[..., slice_number: | |
| 575 | - slice_number + number_slices, ...]) | |
| 576 | - n_image = numpy.empty(shape=(tmp_array.shape[0], | |
| 577 | - tmp_array.shape[2]), | |
| 578 | - dtype=tmp_array.dtype) | |
| 579 | - mips.fast_countour_mip(tmp_array, self.n_border, 1, self.window_level, | |
| 580 | - self.window_level, 1, n_image) | |
| 581 | - elif self._type_projection == const.PROJECTION_CONTOUR_MIDA: | |
| 582 | - tmp_array = numpy.array(self.matrix[..., slice_number: | |
| 583 | - slice_number + number_slices, ...]) | |
| 584 | - n_image = numpy.empty(shape=(tmp_array.shape[0], | |
| 585 | - tmp_array.shape[2]), | |
| 586 | - dtype=tmp_array.dtype) | |
| 587 | - mips.fast_countour_mip(tmp_array, self.n_border, 1, self.window_level, | |
| 588 | - self.window_level, 2, n_image) | |
| 589 | 535 | else: |
| 590 | - n_image = numpy.array(self.matrix[..., slice_number, ...]) | |
| 536 | + #if slice_number == 0: | |
| 537 | + #slice_number = 1 | |
| 538 | + #if slice_number - number_slices < 0: | |
| 539 | + #number_slices = slice_number | |
| 540 | + tmp_array = numpy.array(self.matrix[..., slice_number: slice_number + number_slices, ...]) | |
| 541 | + if inverted: | |
| 542 | + tmp_array = tmp_array[..., ::-1, ...] | |
| 543 | + if self._type_projection == const.PROJECTION_MaxIP: | |
| 544 | + n_image = numpy.array(tmp_array).max(1) | |
| 545 | + elif self._type_projection == const.PROJECTION_MinIP: | |
| 546 | + n_image = numpy.array(tmp_array).min(1) | |
| 547 | + elif self._type_projection == const.PROJECTION_MeanIP: | |
| 548 | + n_image = numpy.array(tmp_array).mean(1) | |
| 549 | + elif self._type_projection == const.PROJECTION_LMIP: | |
| 550 | + n_image = numpy.empty(shape=(tmp_array.shape[0], | |
| 551 | + tmp_array.shape[2]), | |
| 552 | + dtype=tmp_array.dtype) | |
| 553 | + mips.lmip(tmp_array, 1, self.window_level, self.window_level, n_image) | |
| 554 | + elif self._type_projection == const.PROJECTION_MIDA: | |
| 555 | + n_image = numpy.empty(shape=(tmp_array.shape[0], | |
| 556 | + tmp_array.shape[2]), | |
| 557 | + dtype=tmp_array.dtype) | |
| 558 | + mips.mida(tmp_array, 1, self.window_level, self.window_level, n_image) | |
| 559 | + elif self._type_projection == const.PROJECTION_CONTOUR_MIP: | |
| 560 | + n_image = numpy.empty(shape=(tmp_array.shape[0], | |
| 561 | + tmp_array.shape[2]), | |
| 562 | + dtype=tmp_array.dtype) | |
| 563 | + mips.fast_countour_mip(tmp_array, self.n_border, 1, self.window_level, | |
| 564 | + self.window_level, 0, n_image) | |
| 565 | + elif self._type_projection == const.PROJECTION_CONTOUR_LMIP: | |
| 566 | + n_image = numpy.empty(shape=(tmp_array.shape[0], | |
| 567 | + tmp_array.shape[2]), | |
| 568 | + dtype=tmp_array.dtype) | |
| 569 | + mips.fast_countour_mip(tmp_array, self.n_border, 1, self.window_level, | |
| 570 | + self.window_level, 1, n_image) | |
| 571 | + elif self._type_projection == const.PROJECTION_CONTOUR_MIDA: | |
| 572 | + n_image = numpy.empty(shape=(tmp_array.shape[0], | |
| 573 | + tmp_array.shape[2]), | |
| 574 | + dtype=tmp_array.dtype) | |
| 575 | + mips.fast_countour_mip(tmp_array, self.n_border, 1, self.window_level, | |
| 576 | + self.window_level, 2, n_image) | |
| 577 | + else: | |
| 578 | + n_image = numpy.array(self.matrix[..., slice_number, ...]) | |
| 591 | 579 | elif orientation == 'SAGITAL': |
| 592 | 580 | if self._type_projection == const.PROJECTION_NORMAL: |
| 593 | 581 | n_image = numpy.array(self.matrix[..., ..., slice_number]) |
| 594 | - elif self._type_projection == const.PROJECTION_MaxIP: | |
| 595 | - n_image = numpy.array(self.matrix[..., ..., slice_number: | |
| 596 | - slice_number+number_slices]).max(2) | |
| 597 | - elif self._type_projection == const.PROJECTION_MinIP: | |
| 598 | - n_image = numpy.array(self.matrix[..., ..., slice_number: | |
| 599 | - slice_number+number_slices]).min(2) | |
| 600 | - elif self._type_projection == const.PROJECTION_MeanIP: | |
| 601 | - n_image = numpy.array(self.matrix[..., ..., slice_number: | |
| 602 | - slice_number+number_slices]).mean(2) | |
| 603 | - elif self._type_projection == const.PROJECTION_LMIP: | |
| 604 | - tmp_array = numpy.array(self.matrix[..., ..., | |
| 605 | - slice_number: slice_number + number_slices]) | |
| 606 | - n_image = numpy.empty(shape=(tmp_array.shape[0], | |
| 607 | - tmp_array.shape[1]), | |
| 608 | - dtype=tmp_array.dtype) | |
| 609 | - mips.lmip(tmp_array, 2, self.window_level, self.window_level, n_image) | |
| 610 | - elif self._type_projection == const.PROJECTION_MIDA: | |
| 611 | - tmp_array = numpy.array(self.matrix[..., ..., | |
| 612 | - slice_number: slice_number + number_slices]) | |
| 613 | - n_image = numpy.empty(shape=(tmp_array.shape[0], | |
| 614 | - tmp_array.shape[1]), | |
| 615 | - dtype=tmp_array.dtype) | |
| 616 | - mips.mida(tmp_array, 2, self.window_level, self.window_level, n_image) | |
| 617 | - | |
| 618 | - elif self._type_projection == const.PROJECTION_CONTOUR_MIP: | |
| 619 | - tmp_array = numpy.array(self.matrix[..., ..., | |
| 620 | - slice_number: slice_number + number_slices]) | |
| 621 | - n_image = numpy.empty(shape=(tmp_array.shape[0], | |
| 622 | - tmp_array.shape[1]), | |
| 623 | - dtype=tmp_array.dtype) | |
| 624 | - mips.fast_countour_mip(tmp_array, self.n_border, 2, self.window_level, | |
| 625 | - self.window_level, 0, n_image) | |
| 626 | - elif self._type_projection == const.PROJECTION_CONTOUR_LMIP: | |
| 627 | - tmp_array = numpy.array(self.matrix[..., ..., | |
| 628 | - slice_number: slice_number + number_slices]) | |
| 629 | - n_image = numpy.empty(shape=(tmp_array.shape[0], | |
| 630 | - tmp_array.shape[1]), | |
| 631 | - dtype=tmp_array.dtype) | |
| 632 | - mips.fast_countour_mip(tmp_array, self.n_border, 2, self.window_level, | |
| 633 | - self.window_level, 1, n_image) | |
| 634 | - elif self._type_projection == const.PROJECTION_CONTOUR_MIDA: | |
| 582 | + else: | |
| 635 | 583 | tmp_array = numpy.array(self.matrix[..., ..., |
| 636 | 584 | slice_number: slice_number + number_slices]) |
| 637 | - n_image = numpy.empty(shape=(tmp_array.shape[0], | |
| 638 | - tmp_array.shape[1]), | |
| 639 | - dtype=tmp_array.dtype) | |
| 640 | - mips.fast_countour_mip(tmp_array, self.n_border, 2, self.window_level, | |
| 641 | - self.window_level, 2, n_image) | |
| 642 | - else: | |
| 643 | - n_image = numpy.array(self.matrix[..., ..., slice_number]) | |
| 585 | + if inverted: | |
| 586 | + tmp_array = tmp_array[..., ..., ::-1] | |
| 587 | + if self._type_projection == const.PROJECTION_MaxIP: | |
| 588 | + n_image = numpy.array(tmp_array).max(2) | |
| 589 | + elif self._type_projection == const.PROJECTION_MinIP: | |
| 590 | + n_image = numpy.array(tmp_array).min(2) | |
| 591 | + elif self._type_projection == const.PROJECTION_MeanIP: | |
| 592 | + n_image = numpy.array(tmp_array).mean(2) | |
| 593 | + elif self._type_projection == const.PROJECTION_LMIP: | |
| 594 | + n_image = numpy.empty(shape=(tmp_array.shape[0], | |
| 595 | + tmp_array.shape[1]), | |
| 596 | + dtype=tmp_array.dtype) | |
| 597 | + mips.lmip(tmp_array, 2, self.window_level, self.window_level, n_image) | |
| 598 | + elif self._type_projection == const.PROJECTION_MIDA: | |
| 599 | + n_image = numpy.empty(shape=(tmp_array.shape[0], | |
| 600 | + tmp_array.shape[1]), | |
| 601 | + dtype=tmp_array.dtype) | |
| 602 | + mips.mida(tmp_array, 2, self.window_level, self.window_level, n_image) | |
| 603 | + | |
| 604 | + elif self._type_projection == const.PROJECTION_CONTOUR_MIP: | |
| 605 | + n_image = numpy.empty(shape=(tmp_array.shape[0], | |
| 606 | + tmp_array.shape[1]), | |
| 607 | + dtype=tmp_array.dtype) | |
| 608 | + mips.fast_countour_mip(tmp_array, self.n_border, 2, self.window_level, | |
| 609 | + self.window_level, 0, n_image) | |
| 610 | + elif self._type_projection == const.PROJECTION_CONTOUR_LMIP: | |
| 611 | + n_image = numpy.empty(shape=(tmp_array.shape[0], | |
| 612 | + tmp_array.shape[1]), | |
| 613 | + dtype=tmp_array.dtype) | |
| 614 | + mips.fast_countour_mip(tmp_array, self.n_border, 2, self.window_level, | |
| 615 | + self.window_level, 1, n_image) | |
| 616 | + elif self._type_projection == const.PROJECTION_CONTOUR_MIDA: | |
| 617 | + n_image = numpy.empty(shape=(tmp_array.shape[0], | |
| 618 | + tmp_array.shape[1]), | |
| 619 | + dtype=tmp_array.dtype) | |
| 620 | + mips.fast_countour_mip(tmp_array, self.n_border, 2, self.window_level, | |
| 621 | + self.window_level, 2, n_image) | |
| 622 | + else: | |
| 623 | + n_image = numpy.array(self.matrix[..., ..., slice_number]) | |
| 644 | 624 | return n_image |
| 645 | 625 | |
| 646 | 626 | def get_mask_slice(self, orientation, slice_number): | ... | ... |