Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitknnInteractiveBoundingBoxHelpers.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitknnInteractiveBoundingBoxHelpers_h
14 #define mitknnInteractiveBoundingBoxHelpers_h
15 
16 #include <mitkImage.h>
17 #include <mitkPlaneGeometry.h>
19 
20 namespace mitk::nnInteractive
21 {
22  // Computes a tight axis-aligned bounding box in MITK index space around
23  // the non-zero footprint of the 2D painting slice, by mapping the slice's
24  // non-zero 2D bounds through its own geometry into the reference image's
25  // index space. Pads by a couple of voxels to absorb VTK reslicing
26  // boundary effects on axes the stroke spans non-trivially. Works for any
27  // slice orientation (axial / coronal / sagittal / oblique).
28  //
29  // Returns false if the slice has no non-zero pixels or no usable geometry.
30  // On success, outBoundingBox is in nnInteractive's (Z, Y, X) order.
31  //
32  // \pre paintingSlice2D must be a 2D uint8 slice extracted from
33  // referenceImage (i.e. its geometry is related to the reference's
34  // via SegTool2D::GetAffectedImageSliceAs2DImage or equivalent), so
35  // that mapping its 2D index corners through its own IndexToWorld
36  // and back through the reference's WorldToIndex is meaningful.
37  bool ComputeStrokeBoundingBox(const Image* paintingSlice2D,
38  const Image* referenceImage,
39  InteractionBoundingBox& outBoundingBox);
40 
41  // Builds a small 3D uint8 mitk::Image sized exactly to the given bounding
42  // box and transfers the 2D painting slice into it using MITK's plane-aware
43  // VTK reslicing (SegTool2D::WriteSliceToVolume). The returned image's
44  // geometry is derived from the reference image: its origin sits at the
45  // box's first voxel and its spacing/direction match the reference, so
46  // numpy sees it with shape matching the box sizes in nnInteractive's
47  // (Z, Y, X) order.
48  //
49  // The source's non-zero pixels become 1; zero pixels stay 0. Designed for
50  // forwarding to nnInteractive's add_*_interaction(..., interaction_bbox=).
51  //
52  // \pre paintingSlice2D must be a 2D uint8 slice taken at slicingPlane
53  // from referenceImage (typically via SegTool2D), and boundingBox
54  // must be the result of ComputeStrokeBoundingBox on the same
55  // slice/reference pair.
56  Image::Pointer BuildBoundingBoxMaskImage(const Image* paintingSlice2D,
57  const PlaneGeometry* slicingPlane,
58  const Image* referenceImage,
59  const InteractionBoundingBox& boundingBox);
60 }
61 
62 #endif
Image class for storing multi-dimensional medical image data.
Definition: mitkImage.h:76
Describes the geometry of a plane object.
Image::Pointer BuildBoundingBoxMaskImage(const Image *paintingSlice2D, const PlaneGeometry *slicingPlane, const Image *referenceImage, const InteractionBoundingBox &boundingBox)
std::array< std::array< int, 2 >, 3 > InteractionBoundingBox
bool ComputeStrokeBoundingBox(const Image *paintingSlice2D, const Image *referenceImage, InteractionBoundingBox &outBoundingBox)