Ferreroire Ferreroire - 9 months ago 80
Python Question

iPython imshow() or numpy row selection

I'm trying to plot, using imshow(), only the middle hundred rows of an image I have. I was wondering if there are any numpy commands that can slice only the middle hundred rows of my image's array. If not, can I use some variation on imshow() itself to be able to select and show only the middle hundred rows?


What you are looking for is :


example code:

import numpy as np
import matplotlib.pyplot as plt

pic = np.random.rand(300,300)
fig1 = plt.figure()
fig1.suptitle('Full image')
cropped = pic[np.shape(pic)[0]/2-50:np.shape(pic)[0]/2+50,np.shape(pic)[1]/2-50:np.shape(pic)[1]/2+50]
fig2 = plt.figure()
fig2.suptitle('middle 100 rows and column cropped')


enter image description here enter image description here