daiki-kimura
commited on
Commit
•
4c67c33
1
Parent(s):
842ee21
Update open_tiff function for supporting images written by rasterio and tifffile
Browse filesThe new open_tiff function loads by rasterio and tifffile, then choose the best one.
I have tested demo code on my machine with several tif files which generated from rasterio and tifffile
app.py
CHANGED
@@ -14,6 +14,7 @@ from mmseg.models import build_segmentor
|
|
14 |
from mmseg.datasets.pipelines import Compose, LoadImageFromFile
|
15 |
|
16 |
import rasterio
|
|
|
17 |
import torch
|
18 |
|
19 |
from mmseg.apis import init_segmentor
|
@@ -45,13 +46,19 @@ def stretch_rgb(rgb):
|
|
45 |
return img_rescale
|
46 |
|
47 |
|
48 |
-
def open_tiff(fname):
|
49 |
-
|
50 |
with rasterio.open(fname, "r") as src:
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
def write_tiff(img_wrt, filename, metadata):
|
57 |
|
|
|
14 |
from mmseg.datasets.pipelines import Compose, LoadImageFromFile
|
15 |
|
16 |
import rasterio
|
17 |
+
import tifffile
|
18 |
import torch
|
19 |
|
20 |
from mmseg.apis import init_segmentor
|
|
|
46 |
return img_rescale
|
47 |
|
48 |
|
49 |
+
def open_tiff(fname): # it supports images written by rasterio and tifffile
|
|
|
50 |
with rasterio.open(fname, "r") as src:
|
51 |
+
img_rasterio = src.read()
|
52 |
+
|
53 |
+
with tifffile.TiffFile(fname) as tif:
|
54 |
+
img_tifffile = tif.asarray()
|
55 |
+
|
56 |
+
if img_rasterio.shape == img_tifffile.shape:
|
57 |
+
return img_rasterio
|
58 |
+
if img_rasterio.shape[0] == img_tifffile.shape[-1]:
|
59 |
+
return img_rasterio
|
60 |
+
return img_tifffile
|
61 |
+
|
62 |
|
63 |
def write_tiff(img_wrt, filename, metadata):
|
64 |
|