Python Forum
for loop on stacked images
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
for loop on stacked images
#1
Dear All,

I have read each single image from stacked file *.tif separately, using the following code,

dataset = rasterio.open('D:\data_stacked_2015.tif')

fig, (axes1, axes2, axes3) = pyplot.subplots(1,3, figsize=(21,7))
show((dataset, 64), ax = axes1, cmap='gray', title='red channel')
show((dataset, 65), ax = axes2, cmap='gray', title='green channel')
show((dataset, 66), ax = axes3, cmap='gray', title='blue channel')

for ax in axes1, axes2, axes3:
ax.axis('off')
plt.show()

But, What I'd like to do is, to read the whole stacked images as subplot, using for loop, However, the following doesn't work,


dataset = rasterio.open('D:\data_stacked_2015.tif')

# Create subplots
rows, cols = 10, 7
fig, ax = pyplot.subplots(rows, cols,
sharex='col',
sharey='row',
figsize=(21,7))

for axes in range(10):
for col in range(7):
image = show((dataset), axes, cmap='gray')
plt.show()

Any suggestions pleas, and many thanks in advance.
Reply
#2
How could I read the stacked file *.tif separately at once, instead of one by one as below! , using for loop,

Or, How to convert the following code to for loop?

import rasterio
from rasterio.plot import show
from matplotlib import pyplot
import matplotlib.pyplot as plt


# to display bands one by one
dataset = rasterio.open('D:\data_stacked_2015.tif')

fig, (axes1, axes2, axes3) = pyplot.subplots(1,3, figsize=(21,7))
show((dataset, 64), ax = axes1, cmap='gray', title='red channel')
show((dataset, 65), ax = axes2, cmap='gray', title='green channel')
show((dataset, 66), ax = axes3, cmap='gray', title='blue channel')

for ax in axes1, axes2, axes3:
    ax.axis('off')
plt.show()
Reply
#3
Please do not send private mail.
every post is viewed by all moderators, and answered by the first one with the appropriate knowledge.
Reply
#4
Thanks for your reply, Would you please to share your knowledge to solve the above issue, since I'm still in my first steps in python.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020