Python Forum
for loop on stacked images - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: for loop on stacked images (/thread-28626.html)



for loop on stacked images - falahfakhri - Jul-27-2020

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.


for loop to read images - falahfakhri - Jul-27-2020

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()



RE: for loop on stacked images - Larz60+ - Jul-27-2020

Please do not send private mail.
every post is viewed by all moderators, and answered by the first one with the appropriate knowledge.


RE: for loop on stacked images - falahfakhri - Jul-28-2020

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.