Comments (14)
Hi, from the error message it looks like it may be a problem with the format of the image which is causing opencv to be unable to process it.
Can you check the shape (i.e. number of channels) and data type of the images you are trying to use?
Labels need to be added manually
from pathml.
Thanks for your response.
I tried to read the sample image on Pathml (CMU-1.tif). But I get the same error.
from pathml.core import SlideData, SlideType
from pathml.preprocessing import Pipeline, BoxBlur
# load the image
he_type = SlideType(stain="HE", platform=None, tma=False, rgb=True, volumetric=False, time_series=False)
wsi = SlideData(".../CMU-1.tif", slide_type = he_type)
print('wsi', wsi)
pipeline = Pipeline([
BoxBlur(kernel_size=15)
])
from dask.distributed import Client, LocalCluster
cluster = LocalCluster(n_workers=6)
client = Client(cluster)
wsi.run(pipeline, distributed=True, client=client);
Here is the error:
wsi SlideData(name='CMU-1.tif',
slide_type=SlideType(stain=HE, platform=None, tma=None, rgb=True, volumetric=None, time_series=None),
filepath='.../CMU-1.tif',
backend='bioformats',
image shape: (27712, 40000),
number of levels: 7,
0 tiles: [],
0 masks: [],
labels=None,
counts=None)
![Screenshot 2023-07-07 at 2 52 28 PM](https://private-user-images.githubusercontent.com/80137960/251867739-2ecc5c66-2418-407a-be29-05b3c9163fae.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MDcyMTk3MzAsIm5iZiI6MTcwNzIxOTQzMCwicGF0aCI6Ii84MDEzNzk2MC8yNTE4Njc3MzktMmVjYzVjNjYtMjQxOC00MDdhLWJlMjktMDViM2M5MTYzZmFlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDAyMDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwMjA2VDExMzcxMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTJiNzBlOTk5ZmExODI2MTRkNTQ2OGMzNmYyYTM1MDk4Njk4YzhkYzYyY2M3ZDk4ZWM2ZDQ3ZGM1MGMyYTIzM2EmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.8sAF0Dgyl4YKBCt9UfI3ASijmj-X2CqASBkyYZmT4VU)
from pathml.
Update: Since the format of the “CMU-1.tif” image is .tif and Openslide supports this format. I intentionally changed the backend from "bioformats” to "openslide" and did not get the above error.
However, in order to read the image with ome.tiff format, I need to use the backend = "bioformats". Which gives me the same error. It would be great if you could help me with this issue.
from pathml.
Hi,
Looks like the issue is with the file format. Can you share sample files, to replicate the error? I was able to load tiff and ome-tif files without any issue.
from pathml.
@maryamahz what are the version of opencv, javabridge, and bioformats that you have installed in your environment?
Are you able to load any images successfully using the bioformats backend? Can you please try with small_vectra.qptiff?
from pathml.
Thanks for getting back to me. Here are the versions of packages that are installed (I used Docker image to install PathML):
opencv==4.7.0.
bioformats==4.0.0
javabridge==4.0.0
Here is the image I am using as a sample: https://openslide.cs.cmu.edu/download/openslide-testdata/Generic-TIFF/
Could you also please share your codes and sample image, so I can replicate the process?
Yes, As you can see above, I can load/read the images successfully using the Bioformats backend. But when I apply a filter using this command:
wsi.run(pipeline, distributed=True, client=client);
I get the above error.
I also tried on small_vectra.qptiff. But got the same error :(
from pathml.
Here's the code
from pathml.core import SlideData, SlideType
from pathml.preprocessing import Pipeline, BoxBlur
# load the image
he_type = SlideType(stain="HE", platform=None, tma=False, rgb=True, volumetric=False, time_series=False)
wsi = SlideData("../CMU-1.tiff", slide_type = he_type, backend= 'openslide')
print('wsi', wsi)
pipeline = Pipeline([
BoxBlur(kernel_size=15)
])
wsi.plot()
from dask.distributed import Client, LocalCluster
cluster = LocalCluster(n_workers=6)
client = Client(cluster)
wsi.run(pipeline, distributed=True, client=client);
Output
SlideData(name='CMU-1.tiff',
slide_type=SlideType(stain=HE, platform=None, tma=None, rgb=True, volumetric=None, time_series=None),
filepath='../CMU-1.tiff',
backend='openslide',
image shape: (32914, 46000),
number of levels: 9,
22912 tiles: ['(0, 0)', '(0, 1024)', '(0, 10240)', '(0, 10496)', '(0, 10752)', '(0, 11008)', ...],
0 masks: [],
tile_shape=(256, 256, 3),
labels=None,
counts=None)
This worked with small_vectra.qptiff as well. Could you try restarting the kernel?
from pathml.
Thank you for sharing the code.
Yes, this works well for me. As I mentioned before, the reason is that here you are using backend='openslide'.
I believe when the backend is 'openslide', it works well. But I get the above-mentioned error when I want to read/process an image with ome.tiff format that needs to be read by backend = 'bioformats' or when I want to read tiff format with 'bioformats'.
from pathml.
@maryamahz Ultimately this error message you are seeing is coming from openCV, so it is likely due to an incompatibility between your input image and the opencv library. These errors are usually caused when using images with shapes or datatypes not supported by that particular opencv function. So we should be able to reproduce the error using only numpy and opencv, since the error isn't arising from pathml itself.
I tried playing around to see if I could reproduce the error, and I found that it comes up when trying to use box blur on an image with an empty dimension. It works fine for images of shape (n, n, 1), (n, n, 2), (n, n, 3), (n, n, 4), etc... but fails and throws the same error message on an image with shape (n, n, 0). I checked and this is the case for both integer images and float images.
>>> import numpy as np
>>> import cv2
>>> im = np.random.randint(low=0, high=250, dtype=np.uint8, size=(256, 256, 0))
>>> print(f"{im.shape=}")
im.shape=(256, 256, 0)
>>> im_blurred = cv2.boxFilter(im, ksize=(15, 15), ddepth=-1)
Traceback (most recent call last): File "<stdin>", line 1, in <module> cv2.error: OpenCV(4.8.0) /Users/xperience/GHA-OpenCV-Python/_work/opencv-python/opencv-python/opencv/modules/core/src/matrix.cpp:1099: error: (-215:Assertion failed) dims <= 2 && step[0] > 0 in function 'locateROI'
Can you verify the dimensions of the image you are working with?
You can try loading the image, extracting a single tile, looking at the image array contained in the Tile object, and seeing what the shape and datatype of it are. That information would help us get to the bottom of this problem.
Additionally, if you could do the same for both openslide and bioformats backend, we could hopefully find what the difference is in the image array which is causing this problem.
from pathml.
While reading the .tiff format image with ‘bioformats’ the image shape is (256, 256, 1, 3, 1). But with ‘openslide’ the shape is (256, 256, 3). The type for both is unit8.
from pathml.
Ah ok that makes sense!
Yes, the expected behavior for bioformats backend is to return images in (X, Y, Z, C, T) dimensions. But, opencv probably wants your images to have only 3 dimensions (X, Y, C).
To solve, try adding CollapseRunsVectra()
transform as the first step of your pipeline. This transform basically just applies np.squeeze
to collapse the dimensions of size 1
Let me know if this works!
from pathml.
Yes! the error is fixed.
Thanks
from pathml.
Great! Closing this now as resolved, feel free to reopen if it comes up again.
from pathml.
Thanks for your discussion. It is also useful for me.
from pathml.
Related Issues (20)
- How to implement HoVer-Net Model in TIAToolBox?
- Support GPUs on Docker installation
- preprocessing on mrxs file get h5 file full of 0 HOT 6
- necrotic tissue detection for HE and multiplex imaging
- Need assistance with running Pathml package via Colab or Docker and resolving errors HOT 6
- Tests are failing HOT 2
- Error with spams package in vahadane stain normalisation with StainNormalizationHE() HOT 2
- Make a smaller docker image
- Implement Tile Stitching Feature in Image Preprocessing
- Unable to read in all image layers in .vdi file, only index 0 is read in HOT 3
- Use updated openslide v4.0.0 HOT 1
- Add Installation and Setup Instructions for Mamba alongside Conda HOT 1
- http://pathml.org/ image broken HOT 1
- Algorithm for Improved Spectral Unmixing with Reference Image Integration
- add install instructions for windows HOT 1
- Compatibility Query: Using PathML for X-Ray Images with Missing 'TotalPixelMatrixRows' Attribute
- AttributeError pathml.core HOT 8
- pachage install bug
- Unable to Load IMC data (ome.tiff format) properly. Image data appears 0 only...
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pathml.