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

Saving OIB: metadata is lost #27

Open
hmbotelho opened this issue May 16, 2022 · 2 comments
Open

Saving OIB: metadata is lost #27

hmbotelho opened this issue May 16, 2022 · 2 comments
Assignees
Labels

Comments

@hmbotelho
Copy link

When saving this OIB file with RBioFormats the pixel size metadata is lost.

Here's what I did:

library(RBioFormats)
img = read.image("Image0010_01.oib", normalize = FALSE)[,,2]
write.image(img, "Image0010_01.ome.tiff", force = TRUE, pixelType = "uint16")

Doing the equivalent using the bfconvert command line tool preserves the pixel size metadata:

bfconvert Image0010_01.oib Image0010_01.ome.tiff

More info here: https://github.com/hmbotelho/oib_to_tif

@aoles aoles self-assigned this May 16, 2022
@aoles aoles added the bug 🐛 label May 16, 2022
@aoles
Copy link
Owner

aoles commented May 16, 2022

Thanks a lot for reporting this! Actually, when converting an OIB file to OME.TIFF pixel size metadata seems to be preserved both by bfconvert and RBioFormats.

library(RBioFormats)
#> Loading required package: rJava
#> BioFormats library version 6.9.1

fname_oib <- "Image0010_01.oib"
oib <- read.image(fname_oib, normalize = FALSE, subset = list(C = 2))

globalMetadata(oib, pattern = "WidthConvertValue|HeightConvertValue|WidthUnit")
#> $`[Reference Image Parameter] WidthUnit`
#> [1] "um"
#> 
#> $`[Reference Image Parameter] HeightConvertValue`
#> [1] "6.214"
#> 
#> $`[Reference Image Parameter] WidthConvertValue`
#> [1] "6.214"

fname_tif <- sub(".oib", ".ome.tif", fname_oib)
write.image(oib, fname_tif, force = TRUE)
tif <- read.image(fname_tif, normalize = FALSE)

globalMetadata(tif, pattern = "WidthConvertValue|HeightConvertValue|WidthUnit")
#> $`[Reference Image Parameter] WidthUnit`
#> [1] "um"
#> 
#> $`[Reference Image Parameter] HeightConvertValue`
#> [1] "6.214"
#> 
#> $`[Reference Image Parameter] WidthConvertValue`
#> [1] "6.214"

Created on 2022-05-17 by the reprex package (v2.0.1)

Nevertheless, there seem to be some problem in handling of resolution-related metadata entries in the case of plain TIFF files, as illustrated by the following example. I will look into this, so stay tuned.

library(RBioFormats)
#> Loading required package: rJava
#> BioFormats library version 6.9.1

fname_oib <- "Image0010_01.oib"
fname_tif <- sub(".oib", ".tif", fname_oib)

oib <- read.image(fname_oib, normalize = FALSE, subset = list(C = 2))
write.image(oib, fname_tif, force = TRUE)
tif <- read.image(fname_tif, normalize = FALSE)

globalMetadata(tif, pattern = "Resolution")
#> $YResolution
#> [1] 0
#> 
#> $ResolutionUnit
#> [1] "Centimeter"
#> 
#> $XResolution
#> [1] 0

system(sprintf("bfconvert -channel 1 -overwrite %s %s", fname_oib, fname_tif))
tif <- read.image(fname_tif, normalize = FALSE)

globalMetadata(tif, pattern = "Resolution")
#> $YResolution
#> [1] 1609.269
#> 
#> $ResolutionUnit
#> [1] "Centimeter"
#> 
#> $XResolution
#> [1] 1609.269

Created on 2022-05-17 by the reprex package (v2.0.1)

@hmbotelho
Copy link
Author

Thanks for checking this out and comparing TIF and OME.TIFF

Indeed the resolution metadata is stored by RBioFormats, but in a way which is not accessible to Fiji (which my downstream workflow relies on).

I think I found the source of the issue. It sems to be one OME-XML metadata field, which bftools sets as:
<Pixels BigEndian="false" DimensionOrder="XYCZT" ID="Pixels:0" Interleaved="false" PhysicalSizeX="6.214" PhysicalSizeXUnit="µm" PhysicalSizeY="6.214" PhysicalSizeYUnit="µm" PhysicalSizeZ="1.0" PhysicalSizeZUnit="µm" SignificantBits="12" SizeC="2" SizeT="1" SizeX="512" SizeY="512" SizeZ="1" TimeIncrement="1.0" TimeIncrementUnit="s" Type="uint16">

and RBioFormats sets as
<Pixels BigEndian="true" DimensionOrder="XYCZT" ID="Pixels:0" Interleaved="false" SignificantBits="16" SizeC="1" SizeT="1" SizeX="512" SizeY="512" SizeZ="1" Type="uint16">

Is there a way to edit this metadata field in RBioFormats? I checked the Metadata setting functions but did not know how to use them.

Maybe this approach can also help in dealing with plain TIFF files?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants