Closed blowekamp closed 1 year ago
Thanks for reporting this, @blowekamp.
This isn't specific to MRC, and can be more easily reproduced with:
$ bin/bioformats2raw --downsample-type=LINEAR "test&sizeX=257&sizeY=257&pixelType=int8.fake" test.zarr
and
$ bin/bioformats2raw --downsample-type=LINEAR "test&sizeX=256&sizeY=257&pixelType=int8.fake" test.zarr
Both of these work though:
$ bin/bioformats2raw --downsample-type=LINEAR "test&sizeX=256&sizeY=256&pixelType=int8.fake" test-int8.zarr
$ bin/bioformats2raw --downsample-type=LINEAR "test&sizeX=256&sizeY=257&pixelType=uint8.fake" test-uint8.zarr
which suggests that it's a combination of pixel type and image size. I don't have an immediate idea of why happens, so we'll need to investigate further.
Thanks you for looking into this.
Oddly using 3dmod's newstack
command to convert this sample to uint8 it worked. However, the real data I have still produces the same error after conversion to uint8.
$ header out_uint8.mrc
RO image file on unit 1 : out_uint8.mrc Size= 19823 K
Number of columns, rows, sections ..... 4969 4085 1
Map mode .............................. 0 (byte)
Start cols, rows, sects, grid x,y,z ... 0 0 0 4969 4085 1
Pixel spacing (Angstroms).............. 1.000 1.000 1.000
Cell angles ........................... 90.000 90.000 90.000
Fast, medium, slow axes ............... X Y Z
Origin on x,y,z ....................... 0.000 0.000 0.000
Minimum density ....................... 9.0000
Maximum density ....................... 255.00
Mean density .......................... 69.923
tilt angles (original,current) ........ 0.0 0.0 0.0 0.0 0.0 0.0
Space group,# extra bytes,idtype,lens . 0 0 0 0
2 Titles :
tif2mrc: Converted to MRC format. 03-Apr-23 11:53:49
NEWSTACK: Images copied 3-Apr-23 11:54:07
$ ~/scratch/bioformats2raw-0.6.1/bin/bioformats2raw out_uint8.mrc --compression=null --downsample-type AREA test.zarr --progress
[0/0] 100% │█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████│ 20/20 (0:00:00 / 0:00:00)
[0/1] 0% │ │ 0/6 (0:00:00 / ?)
2023-04-03 11:56:18,839 [pool-1-thread-1] ERROR c.g.bioformats2raw.Converter - Failure processing chunk; resolution=1 plane=0 xx=0 yy=1024 zz=0 width=1024 height=1018 depth=1
org.opencv.core.CvException: cv::Exception: OpenCV(3.4.2) /Users/jason/Projects/openpnp/opencv/opencv/opencv-3.4.2/modules/imgproc/src/resize.cpp:3881: error: (-215:Assertion failed) func != 0 && cn <= 4 in function 'resize'
at org.opencv.imgproc.Imgproc.resize_0(Native Method)
at org.opencv.imgproc.Imgproc.resize(Imgproc.java:2921)
at com.glencoesoftware.bioformats2raw.OpenCVTools.opencvDownsample(OpenCVTools.java:172)
at com.glencoesoftware.bioformats2raw.OpenCVTools.downsample(OpenCVTools.java:115)
at com.glencoesoftware.bioformats2raw.Converter.getTileDownsampled(Converter.java:1046)
at com.glencoesoftware.bioformats2raw.Converter.getTile(Converter.java:1078)
at com.glencoesoftware.bioformats2raw.Converter.processChunk(Converter.java:1179)
at com.glencoesoftware.bioformats2raw.Converter.lambda$saveResolutions$4(Converter.java:1387)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:750)
However, the real data I have still produces the same error after conversion to uint8.
Can you check that bioformats2raw is actually recognizing the converted data as uint8? grep 'Type="uint8"' test.zarr/OME/METADATA.ome.xml
should result in a match if uint8 is being detected correctly.
Potentially related issue on the OpenCV side: https://github.com/opencv/opencv/issues/7862
Can you check that bioformats2raw is actually recognizing the converted data as uint8?
grep 'Type="uint8"' test.zarr/OME/METADATA.ome.xml
should result in a match if uint8 is being detected correctly.
The ome.xml contains Type="int8"
. So the pixel type is not being detected correctly.
Potentially related issue on the OpenCV side: opencv/opencv#7862 That sounds like what has been encountered.
The ome.xml contains Type="int8". So the pixel type is not being detected correctly.
That's a Bio-Formats issue then, and we'd need to see the original data to investigate. If you're comfortable sharing publicly, you can post a download link here, otherwise you can message the OME team privately with a link.
Potentially related issue on the OpenCV side: https://github.com/opencv/opencv/issues/7862 That sounds like what has been encountered.
Since it doesn't look like there is a version of OpenCV that supports these data types, probably the best we can do at the moment is issue a more informative warning or error in bioformats2raw.
Please find a synthetic image attached of [0-99] pixels as a10x10 uint8 mrc file.
$ tif2mrc -B 0 slice.tiff test_uint8.mrc
Opening slice.tiff for input
Min = 0, Max = 99, Mean = 49.5
$ header test_uint8.mrc
RO image file on unit 1 : test_uint8.mrc Size= 1 K
Number of columns, rows, sections ..... 10 10 1
Map mode .............................. 0 (byte)
Start cols, rows, sects, grid x,y,z ... 0 0 0 10 10 1
Pixel spacing (Angstroms).............. 1.000 1.000 1.000
Cell angles ........................... 90.000 90.000 90.000
Fast, medium, slow axes ............... X Y Z
Origin on x,y,z ....................... 0.000 0.000 0.000
Minimum density ....................... 0.0000
Maximum density ....................... 99.000
Mean density .......................... 49.500
tilt angles (original,current) ........ 0.0 0.0 0.0 0.0 0.0 0.0
Space group,# extra bytes,idtype,lens . 0 0 0 0
1 Titles :
tif2mrc: Converted to MRC format. 04-Apr-23 10:10:24
Closing as the upcoming bioformats2raw
release should address both issues: incorrect pixel type detection for MRC by Bio-Formats and unsupported OpenCV downsampling
The following is the exception I am encountering:
This does not occur with the "SIMPLE" downsampled, but the others based on openCV do.
I was unable to directly create a MRC file to reproduce the error. But the following produces the out.mrc which creates the error:
Python:
Note: It appears the size needs to be >256, as a tiff file of 256x256 seems to work OK.
Using 3dmod's tif2mrc: