Hi guys, I need to read a 32bit tiff and wonder if it is possible to use imageio (or similar packages)
but I have now idea about how to install them. Can you please help me out?
Yes, it is possible to use the ImageIO library to read a 32-bit TIFF image. ImageIO is a built-in library in Java which supports a wide variety of image formats, including TIFF.
To use ImageIO, you will need to have Java installed on your machine. Then, you can use the following code snippet to read a 32-bit TIFF image:
image = imageio.imread("path/to/image.tiff")
Keep in mind that the imageio.imread()
function returns a 3D array of shape (num_frames, height, width).
There’s a pop-up that tells you how to install ImageIO for CPython in Rhino WIP
When you use a template to start a new Python script it tells you how you can add dependencies in that script.
- You can specify your script requirements like:
# r: <package-specifier> [, <package-specifier>]
# requirements: <package-specifier> [, <package-specifier>]
For example this line will ask the runtime to install
the listed packages before running the script:
# requirements: pytoml, keras
You can install specific versions of a package
using pip-like package specifiers:
# r: pytoml==0.10.2, keras>=2.6.0
You should be able to specifiy imageio · PyPI for your needs.
Thanks, I managed to install RasterIO which doesn’t require Java so now I am checking that out.
Cheers!
The way I showed uses the Python package imageio
. This package does not require Java.
You shouldn’t need to do anything special beyond the # requirements: imageio
in your script in RhinoCode.
#! python3
# requirements: imagio
import imageio
im = imageio.imread('/Users/nathan/Desktop/tifftest2.tiff')
print(im.shape)
That is a simple script I used to test loading of the pure-Python module imageio
.
Nice, I didn’t know and will try that out!
It appears you have imageio already installed, I just tested this on my homecomputer now and I got this result:
Here is how I installed rasterio for and from Rhino on my home computer:
#! python3
# r: os
### "pip install rasterio"
import os
homePath = os.path.expanduser('~')
command = homePath + "\.rhinocode\python3.9-1.25\Scripts\pip install rasterio"
os.system('cmd /c '+str(command))
And the same works for imageio:
#! python3
# r: os
### "pip install imageio"
import os
homePath = os.path.expanduser('~')
command = homePath + "\.rhinocode\python3.9-1.25\Scripts\pip install imageio"
os.system('cmd /c '+str(command))
``
I doubt that is how it is “supposed” to work and that Nathan’s example should have done the install for you. @eirannejad would be the best person to give the correct answer here though since he wrote all of this.
@Holo Try the snippet below
-
# r: imageio
specified you need this package and the code editor automatically handles thepip install
- You don’t need to specify builtin packages e.g.
# r: os
might cause problems.os
is a builtin python module not a PyPi package.
# r: imageio
import imageio
print(imageio)
I tried Nathans code directly as it was written, except I changed the typo “# requirements: imagio” to “# requirements: imaegio”
Hello @eirannejad ! Does the #r
directive support NuGet or Pip references?
Sorry the answer is above…
I had to restart my Rhino 8 WIP for installed requirements to work. (poke for @eirannejad)
Yeah that happens sometimes. I have to dig deep in Pythonnet’s code to find out why
I have a YT for that here RH-68940
EDIT:
OK, I have tested this both on my workstation and my home machine, both have had WIP on for a long time. On neither of these did this work, and they had new updates for the WIP, so nothing old there.
But I tested now on the laptop which did not have had Rhino 8 installed before and it worked right out of the box.
Guess I need to uninstall and clear out WIP from the other machines and install it again.
Probably some old junk that prevented it from working.
Thanks for the help, wish it worked right away so I hadn’t wasted hours on figuring this out, but I learned somehting, and hopefully it is of use to you too to know that it didn’t work on those machines where WIP has been upgraded many times.
Edit 2:
I tried it with rasterio too, but that didn’t work. So I tried the restart RhinoWIP advice and then it worked. That’s strange, are there any (for us) logical reasons for why it shouldn’t be able to install both in one session of Rhino?
# r: rasterio
import rasterio
print(rasterio)