You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix inverse masking in MRXS files due to transparency handling
Issue Description
When processing MRXS files, the tissue masking algorithm produces inverted masks where background is incorrectly identified as tissue. This occurs because MRXS files contain transparent pixels in the scanning area, and this is represented as black with current RGBA->RGB handling, which OTSU thresholding then recognized to be foreground.
Can't post images because they are not public.
Root Cause
MRXS files contain large scanning areas with transparent pixels (alpha channel)
The current code truncates the alpha channel with np.array(image)[..., :3], converting transparent pixels to black
During masking, these black areas are incorrectly identified as tissue, resulting in an inverse mask
Technical Details
In wsi_handler.py, both read_region and get_full_img methods discard the alpha channel:
# Current implementationregion=self.file_ptr.read_region(new_coord, self.read_lv, size)
returnnp.array(region)[..., :3] # Discards alpha, transparent pixels become black
Solution
Add a static helper method to FileHandler that properly handles transparency by compositing RGBA images with a white background:
Then update the relevant methods to use this helper:
# In read_region and get_full_imgregion_pil=self.file_ptr.read_region(new_coord, self.read_lv, size)
returnself.pil_to_rgb_array(region_pil)
Considerations
We explored
Simple alpha truncation (original approach) - caused the issue
PIL's convert('RGB') - didn't properly handle transparency in MRXS files
I can't think of negative side effects, since performance effect is negligible, and I don't know of any usage of transparency in WSI formats that is not to represent unscanned tissue.
The text was updated successfully, but these errors were encountered:
Fix inverse masking in MRXS files due to transparency handling
Issue Description
When processing MRXS files, the tissue masking algorithm produces inverted masks where background is incorrectly identified as tissue. This occurs because MRXS files contain transparent pixels in the scanning area, and this is represented as black with current RGBA->RGB handling, which OTSU thresholding then recognized to be foreground.
Can't post images because they are not public.
Root Cause
np.array(image)[..., :3]
, converting transparent pixels to blackTechnical Details
In
wsi_handler.py
, bothread_region
andget_full_img
methods discard the alpha channel:Solution
Add a static helper method to
FileHandler
that properly handles transparency by compositing RGBA images with a white background:Then update the relevant methods to use this helper:
Considerations
convert('RGB')
- didn't properly handle transparency in MRXS filesI can't think of negative side effects, since performance effect is negligible, and I don't know of any usage of transparency in WSI formats that is not to represent unscanned tissue.
The text was updated successfully, but these errors were encountered: