[SciPy-user] box extracting

Fernando Perez Fernando.Perez at colorado.edu
Thu Jul 22 14:24:57 CDT 2004

Eric Joseph Bubar wrote:
> Hello,
> I am new to computer programming and python.  I have been using it for 
> around 4 weeks, so my knowledge is VERY limited.  I have a 512x512 
> image.  I want to take a boxed chunk of this image to analyze with the 
> 2D FFT.  Basically I need to make a box of this image of dimensions 
> (100x100) centered on the middle of the image.  Everything out of this 
> box, i want to get rid of.  Any advice on how to do this would be 
> greatly appreciated.  Thanks

This should get you off the ground.  I'm being unnecessarily explicit in the 
bound calculations for the sake of clarity:

In [1]: img=RA.random((512,512))

In [2]: img.shape
Out[2]: (512, 512)

In [3]: bound_low,bound_hi = 512/2-100/2, 512/2+100/2

In [4]: sub_image = img[bound_low:bound_hi,bound_low:bound_hi]

In [5]: sub_image.shape
Out[5]: (100, 100)



More information about the SciPy-user mailing list