Skip to content

Commit

Permalink
Updated to version 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammedSunoqrot committed Jun 26, 2024
1 parent 4b69b11 commit 3baf74f
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 231 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ This python version is differ than the originally published MATLAB version [http
- In detection post-processing, a morphological erosion step follows the opening has been added with kernel radius of 5 pixels.
- The 95th and 5th percentile of the fat and muscle intensities, respectively, were used to normalize the image.

**`VERSION 2.1.0 and above`**
- In case of non-detected fat or muscle objects, the 3 middel slices will be selected, and the normalization will be done using the intensity be calculated using the 95th and 5th percentile of the entire pre-prccessed 3 slices.


# How to cite AutoRef/pyAutoRef
In case of using or refering to AutoRef/pyAutoRef, please cite it as:
```
Expand Down
Binary file removed dist/pyAutoRef-2.0.2-py3-none-any.whl
Binary file not shown.
Binary file removed dist/pyautoref-2.0.2.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pyAutoRef
version = 2.0.2
version = 2.1.0
author = Mohammed R. S. Sunoqrot
author_email = [email protected]
description = Python pakage to perfom AutoRef (prostate T2w MRI dual reference tissue [fat and muscle] normalization).
Expand Down
198 changes: 0 additions & 198 deletions src/pyAutoRef.egg-info/PKG-INFO

This file was deleted.

17 changes: 0 additions & 17 deletions src/pyAutoRef.egg-info/SOURCES.txt

This file was deleted.

1 change: 0 additions & 1 deletion src/pyAutoRef.egg-info/dependency_links.txt

This file was deleted.

7 changes: 0 additions & 7 deletions src/pyAutoRef.egg-info/requires.txt

This file was deleted.

1 change: 0 additions & 1 deletion src/pyAutoRef.egg-info/top_level.txt

This file was deleted.

13 changes: 7 additions & 6 deletions src/pyAutoRef/autoref.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pyAutoRef.object_detection import object_detection
from pyAutoRef.post_processing import post_process_predictions
from pyAutoRef.normalization import normalize_image
from pyAutoRef.utils import save_image, check_predictions, check_input_image
from pyAutoRef.utils import save_image, check_predictions, check_input_image, get_intensities_without_detection

"""
This is the python version of the:
Expand Down Expand Up @@ -83,12 +83,13 @@ def autoref(input_image, output_image_path=None):
# Check again after recalculating
class_with_zero_predictions = check_predictions(top_predictions)

# If still any class has zero predictions, raise an error
# If still any class has zero predictions, normalize without detection
if class_with_zero_predictions:
raise ValueError(f"No detected objects for {class_with_zero_predictions}.")

# Perform post-processing to the detected objects
processed_images_intensities = post_process_predictions(
print(f"Objects still not detected. Recalculating intensities without detection...")
processed_images_intensities = get_intensities_without_detection(resized_corrected_image)
else:
# Perform post-processing to the detected objects
processed_images_intensities = post_process_predictions(
resized_corrected_image, top_predictions)

# Perform normalization
Expand Down
46 changes: 46 additions & 0 deletions src/pyAutoRef/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,3 +942,49 @@ def check_input_image(input_image):
return 'Path'
else:
raise ValueError("The entered value is not a SimpleITK.Image or a valid path.")

def get_intensities_without_detection(image_3D):
"""
Process the 3D image to get the intensities within the selected 3 middle slices.
Parameters:
image_3D (SimpleITK.Image): The 3D image containing the slices.
Returns:
processed_images_intensities (numpy.ndarray): An array contains all the intensites
within the selected 3 middle slices.
"""
# Detect and remove outliers in the 3D image
image_3D_wo_outliers = detect_remove_outliers(image_3D)

# Get the size of the image
size = image_3D_wo_outliers.GetSize()

# Determine the central slices
central_slice_indices = [size[2] // 2 - 1, size[2] // 2, size[2] // 2 + 1]

# Initialize an empty list to store non-zero intensities
non_zero_intensities = []

# Loop through the central slices and extract non-zero intensities
for index in central_slice_indices:
# Extract the 2D slice
slice_image = image_3D_wo_outliers[:, :, index]
# Convert to numpy array
slice_array = sitk.GetArrayFromImage(slice_image)
# Get non-zero intensities
non_zero_values = slice_array[slice_array > 0]
# Append the non-zero values to the list
non_zero_intensities.extend(non_zero_values)

# Convert the list to a numpy array
non_zero_intensities_array = np.array(non_zero_intensities)

# Convert the list of intensities to a NumPy array and store in the dictionary
# Duplicate the array to have one array with 2 classes
processed_images_intensities = {}
processed_images_intensities['fat'] = np.array(non_zero_intensities_array)
processed_images_intensities['muscle'] = np.array(non_zero_intensities_array)

# Return the intensities arrays of the detected classes objects
return processed_images_intensities

0 comments on commit 3baf74f

Please sign in to comment.