Bottom Page

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.
Larz60+ wrote Jul-27-2020, 11:13 AM:
Please post all code, output and errors (in it's entirety) between their respective tags. Refer to BBCode help topic on how. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Forum rules, Buran wanred you of this on your last post

Please do this, thank you.
Quote
#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()
Quote
#3
Please do not send private mail.
every post is viewed by all moderators, and answered by the first one with the appropriate knowledge.
Quote
#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.
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)