Skip to content

Commit

Permalink
Reading TIF file
Browse files Browse the repository at this point in the history
Function to read TIF file, and extracting crucial geographical and dimensional information, and converting them into a manipulable format for further analysis and processing.
  • Loading branch information
dhiraj-ms committed Feb 27, 2024
1 parent ec7f043 commit 3473b67
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ dynamic = ["version"]
dependencies = [
"plantcv",
"matplotlib",
"jupyterlab",
"rasterio",
]
requires-python = ">=3.6"
authors = [
Expand Down
37 changes: 37 additions & 0 deletions readtifimage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#Read TIF image

import rasterio


def readimage(filepath):
"""Read TIF image from file.
Inputs:
filepath = path of TIF image file
Returns:
imagearray = image object as numpy array
crs = coordinate reference system
width = width of digital number array values
height = height of digital number array values
bands = total number of bands in image
bounds = spatial extent of the image mapped on the earth's surface
:param filename: str
:return imagearray: numpy.ndarray
:return crs: rasterio.crs.CRS
:return width: int
:return height: int
:return bands: int
:return bounds: rasterio.coords.BoundingBox
"""
img = rasterio.open(filepath)
inputarray = img.read()
crs = img.crs
width = img.width
height = img.height
bands = img.count
bounds = img.bounds

return inputarray, crs, width, height, bands, bounds

0 comments on commit 3473b67

Please sign in to comment.