osirix.dcm_pix
Provides functionality for the images displayed in a 2D OsiriX viewer.
Example usage
import osirix
import matplotlib.pyplot as plt
viewer = osirix.frontmost_viewer() # Raises GrpcException error if no viewer is available.
pix = viewer.cur_dcm() # Get the currently displayed DCMPix object
plt.imshow(pix.image, cmap = "gray") # Display the image data (pix.image is a 2D numpy array)
plt.show()
DCMPix
Bases: OsirixBase
image: NDArray
property
writable
The image data as a Numpy array.
If the image is RGB format, then the shape will be (rows, columns, 4), whereas if the image
is greyscale format it will be shape (rows, columns) (see is_rgb
property).
is_rgb: bool
property
Is the image data red-green-blue? If False
must be greyscale.
orientation: NDArray
property
The orientation of the image.
NOTE: It can be more accurate to get the slice location by loading the dicom file via the
source_file
property (using pydicom for example), and using the ImageOrientationPatient
tag.
origin: Tuple[float, float, float]
property
The origin of the image (x, y, z).
NOTE: It can be more accurate to get the slice location by loading the dicom file via the
source_file
property (using pydicom for example), and using the ImagePositionPatient tag.
pixel_spacing: Tuple[float, float]
property
The pixel spacing of the image (order: rows, columns)
shape: Tuple[int, int]
property
The pixel shape of the image (order: rows, columns)
slice_location: float
property
The slice location of the image.
NOTE: It can be more accurate to get the slice location by loading the dicom file via the
source_file
property (using pydicom for example), and using the ImagePositionPatient tag.
source_file: str
property
The source file of the image on the host machine.
compute_roi(roi)
Compute some statistics from an ROI contained within the image.
Note that these are calculated internally by OsiriX. For more refinement on how statistics
are calculated we suggest that it is better to create your own tools (based on the
scipy.stats
library for example).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
roi |
ROI
|
The region of interest from which to compute the statistics. |
required |
Returns:
Type | Description |
---|---|
Dict
|
A dictionary containing the following key-value pairs: "mean", "std", "min", "max", "skewness", "kurtosis" |
convert_to_bw(mode=3)
Convert the image to greyscale.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mode |
int
|
0 = use red channel, 1 = use green channel, 2 = use blue channel, and 3 = merge. |
3
|
convert_to_rgb(mode=3)
Convert the image to RGB.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mode |
int
|
0 = create red channel, 1 = create green channel, 2 = create blue channel, and 3 = create all channels. |
3
|
get_map_from_roi(roi)
Create a mask from an input ROI based on the image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
roi |
ROI
|
The ROI from which to extract the mask. |
required |
Returns:
Type | Description |
---|---|
NDArray
|
The mask as a 2-dimensional binary array with shape (rows, columns). |
get_roi_values(roi)
Extract the pixel values within a region of interest.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
roi |
ROI
|
The ROI from which to extract values. |
required |
Returns:
Type | Description |
---|---|
NDArray
|
The row indices of the extracted values. |
NDArray
|
The columns indices of the extracted values. |
NDArray
|
The extracted pixel values. |
image_obj()
The DicomImage
instance from which the image was derived.
Returns:
Type | Description |
---|---|
DicomImage
|
The image instance. |
series_obj()
The DicomSeries
instance from which the image was derived.
Returns:
Type | Description |
---|---|
DicomSeries
|
The series instance. |
study_obj()
The DicomStudy
instance from which the image was derived.
Returns:
Type | Description |
---|---|
DicomStudy
|
The study instance. |