Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📝 [skip ci] DOC: DFBR Jupyter Notebook revised #494

Merged
merged 196 commits into from
Dec 19, 2022

Conversation

ruqayya
Copy link
Contributor

@ruqayya ruqayya commented Oct 20, 2022

No description provided.

ruqayya and others added 30 commits July 30, 2022 17:31
Co-authored-by: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com>
Co-authored-by: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com>
Co-authored-by: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com>
- Fix indents
- init files is added
- cv2 imresize is replaced with the tiatoolbox resize ftn
…istration.py, due to an error 'fixture not found'.
- Merge develop into dev-feature_extraction_DFBR.
- Move fixtures to conftest.py
- Move fixtures to conftest.py
Co-authored-by: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com>
Copy link
Contributor Author

ruqayya commented Dec 9, 2022

These saved images are used in segmentor.predictor. This is due to the limitation of this function which is it currently accepts path to the images as an argument instead of image numpy array.


View entire conversation on ReviewNB

Copy link
Contributor Author

ruqayya commented Dec 9, 2022

Update this section as:

In this section, image segmentation is performed to generate tissue masks so that registration can be performed using only the active or discriminatory tissue area. In DFBR, these are used to exclude the matching points from the non-tissue and fatty regions while in the non-rigid alignment method, the background region is excluded from images before inputting them to the SimpleITK module.

Here, we use the TIAToolbox semantic segmentor and its built-in model for tissue segmentation. We should mention that when you use a TIAToolbox pretrained model, you don't need to worry about setting the input/output shape parameters as their optimal values will be loaded by default. For more detailed information on semantic segmentor, readers are referred to a semantic segmentation example notebook.


View entire conversation on ReviewNB

Copy link
Contributor Author

ruqayya commented Dec 9, 2022

For clarity, I have updated the comment. Since, we only need to map the computed transform to level 0 and not in between the magnification level, I am keeping it as it as for now, instead of a function.

# DFBR transform is computed for level 6 and hence should be mapped to level 0 for AffineWSITransformer

dfbr_transform_level = 6

transform_level0 = dfbr_transform * [

[1, 1, 2**dfbr_transform_level],

[1, 1, 2**dfbr_transform_level],

[1, 1, 1],

]


View entire conversation on ReviewNB

Copy link
Contributor Author

ruqayya commented Dec 9, 2022

Updated it as:

Non-rigid registration using B-spline Transform

Histology slides mostly have non-linear deformations that cannot be tackled with a global rigid transformation alone. On the other hand, non-rigid registration methods are capable of finding correspondence by locally transforming a moving image. These methods require two images to be linearly aligned before their application. In this section, we perform non-rigid B-spline registration of linearly aligned fixed and moving tiles using a multi-resolution approach. The moving image here is a registered tile after the application of the DFBR transform, as shown above. For any given image pair, this method is shown to perform better with the inverted intensity values. The B-spline approach involves a number of parameters that the user can experiment with. Changing these parameters would result in varying complexity and registration completion times. Feel free to play around with the non-rigid alignment parameters and experiment with new images.


View entire conversation on ReviewNB

Copy link
Contributor Author

ruqayya commented Dec 9, 2022

Updated it as:

Now, we apply the B-Spline transform to the linearly aligned moving tile. To apply the transform, a resampling operation is performed. For comparison purposes, overlaid images of fixed and moving tiles before and after the application of the B-spline transform are presented below.


View entire conversation on ReviewNB

Copy link
Contributor Author

ruqayya commented Dec 9, 2022

def preprocess_image(image):

"""This function converts the RGB image to grayscale image and

improves the contrast by linearly rescaling the values.

"""

image = color.rgb2gray(image)

image = exposure.rescale_intensity(

image, in_range=tuple(np.percentile(image, (0.5, 99.5)))

)

image = image * 255

return image.astype(np.uint8)


View entire conversation on ReviewNB

Copy link
Contributor Author

ruqayya commented Dec 9, 2022

Updated it as:

In this example, we will show how to use TIAToolbox for registration of a pair of histology images. Registration refers to aligning a pair of images where one of the images is referred to as the fixed image while the other image is referred as the moving image. The moving image is spatially transformed so that it aligns with the fixed image. Registration often serves as an essential pre-processing step for many medical image analysis tasks. Registration of multiple sections in a tissue block is an important pre-requisite task before any cross-slide image analysis.

We perform registration of an image pair using Deep Feature Based Registration (DFBR) [1], followed by non-rigid alignment using SimpleITK. The registration tool in the TIAToolbox also comprises a pre-alignment step, pre-requisite to DFBR. In particular, we will introduce the use of our registration tool wsi_registration.

[1] Awan, Ruqayya, et al. "Deep Feature based Cross-slide Registration." arXiv preprint arXiv:2202.09971 (2022).


View entire conversation on ReviewNB

Copy link
Contributor Author

ruqayya commented Dec 9, 2022

Added: The overlaid image of fixed and moving images on the right side shows a better overlap of histological structures as compared to the overlaid image on the left side. This is because the B-spline approach identifies the local deformations in the tissue and hence further improves the alignment by transforming the moving image locally. The most noticeable improvement can be seen on the bottom left side and at the top of the glandular tissue area.


View entire conversation on ReviewNB

Copy link
Contributor Author

ruqayya commented Dec 9, 2022

Now, we will find a bit more details in this section's description along with links to the B-spline approach. I have added a documentation link for details on the list of parameters.


View entire conversation on ReviewNB

Copy link
Collaborator

Oh, in that case, why not using the WSI path in the predictor in wsi mode? It's better to feed in the WSI into the predictor rather than the thumbnail. That would be more inline with what we have shown before in Semantic Segmentor and you don't need to provide any other arguments to predict function (although you need to check if it works). It think that's the best way to show TIAToolbox capabilities, however, if you think this way is clearer, I'm happy with it.


View entire conversation on ReviewNB

@review-notebook-app
Copy link

review-notebook-app bot commented Dec 9, 2022

View / edit / reply to this conversation on ReviewNB

mostafajahanifar commented on 2022-12-09T14:31:10Z
----------------------------------------------------------------

Line #13.            os.path.join(global_save_dir, "fixed.png"),

here insread of path to thubmnail you can use path to wsis, and then use the predict function in wsi mode. You need to be careful about the output resolution tho.

This is just a suggestion in regard to my last comment, feel free to ignore it.


ruqayya commented on 2022-12-14T14:42:20Z
----------------------------------------------------------------

As mentioned above, thumbnails are preprocessed images.

@review-notebook-app
Copy link

review-notebook-app bot commented Dec 9, 2022

View / edit / reply to this conversation on ReviewNB

mostafajahanifar commented on 2022-12-09T14:31:11Z
----------------------------------------------------------------

It also seems to me that the output images from the code blocks are removed now. You need to run the notebook and save it with the outputs generated before pushing to github. (don't need to show output for the couple of first cells that are responsible for toolbox installation.)


Copy link
Member

#510 is merged now. Please can you check this again?


View entire conversation on ReviewNB

Copy link
Member

We are looking into this in #519


View entire conversation on ReviewNB

1 similar comment
Copy link
Member

We are looking into this in #519


View entire conversation on ReviewNB

Copy link
Contributor Author

ruqayya commented Dec 14, 2022

These thumbnails are preprocessed images and hence we cannot give WSI path to the predictor unless we include preprocessing steps into the Semantic Segmentor.


View entire conversation on ReviewNB

Copy link
Contributor Author

ruqayya commented Dec 14, 2022

I can't find this class in the documentation. Can you please share the link?


View entire conversation on ReviewNB

Copy link
Contributor Author

ruqayya commented Dec 14, 2022

As mentioned above, thumbnails are preprocessed images.


View entire conversation on ReviewNB

Copy link
Collaborator

well if the goal is to find the tissue mask, the SemanticSegmentor does not need processed images to find the tissue mask and can do this directly from the the WSI object. However, it's ok to leave the code as it is for now.


View entire conversation on ReviewNB

Copy link
Collaborator

@mostafajahanifar mostafajahanifar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @ruqayya for doing this PR. It looks fine to be merged for the next coming release.

@shaneahmed shaneahmed merged commit 5eec6a3 into develop Dec 19, 2022
@shaneahmed shaneahmed deleted the DFBR_notenook_revised branch December 19, 2022 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants