grabbing a region via python

David Gutman dagutman at gmail.com
Sat Feb 9 15:36:40 EST 2013


Had a quick question about cropping out regions using the python
interface--  I'm trying to just crap a couple of tiles and just wanted to
make sure I am interpreting the coordinate frames properly...

So I have a slide I scanned at 40X... and I want to tile it at 20X.  So I
want something downsampled by a factor of two...

img.level_downsamples =  (1.0, 4.0, 16.00027570995313, 32.00355329607886)


 mynewimage = img.read_region( [4096,4096],0,[4096,4096])

"location: (x, y) tuple giving the top left pixel in the level 0
          reference frame.
level:    the level number.
size:     (width, height) tuple giving the region size.

Unlike in the C interface, the image data returned by this
function is not premultiplied."


So I just wanted to double check--- in my case I want to "tile" at
20X... but while the software can pull out that information... I am
not using "those" numbers to pick my region.. I am using 0,1,2,3...


In this case.. since the regions are 1,4,16, and 32... that would
correspond to 40X, 10X, 2.5X and 1.25X....

So in my case--- if I did read_region I would grab layer 0.... and
then say I get a 4K box with the upper left corner at 4096,4096....
I'd then have to decimate that image by a power of two to make it a
"20X" tile...

Or is there a function that will do this for me automatically..




Also... I wanted to clarify exactly what "tuple giving the top left
pixel in the level 0 reference frame." Means..



So if I specified layer 0 for read region... say I specify 10,000,
1000 as the upper X corner.... and then 4K by 4K as the bounding box..


It would return a PIL object that's 4Kx4K.... and would represent the
cropped region from 10,000,10,000 -->  14096,14096


In the second example...if I specified the upper coord of 10Kx10K...
but used region 1 as the level to grab... I'd still get a 4Kx4K output
but instead would be a lower resolution image... and go from
10,000,10000 --> 26384/26384 in "ref frame 0 coordinate) but in "ref
frame 1" coordinates would be from 1024,1024 -> (5120,5120)

Thanks!


Also is there a function that would "grab" the 20X tiles... I may have
missed it in the API documentation....












-- 
David A Gutman, M.D. Ph.D.
Assistant Professor of Biomedical Informatics
Senior Research Scientist, Center for Comprehensive Informatics
Emory University School of Medicine
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.andrew.cmu.edu/pipermail/openslide-users/attachments/20130209/b714313b/attachment.html 


More information about the openslide-users mailing list