I want to ask how to Extract the a n×n image segment from an input image centered around the position (x,y), the image has format like this [[num,num,num],[num,numm,num],[num,num,num]........], size of image is about 10 * 10. Thank you !
Extract the 3×3image segment from the input image centred around the position (x,y)
26 Views Asked by Amaranta Arcadio At
2
There are 2 best solutions below
0
On
Question. So you wish to find the center of an image, expand 1 pixel left, left down, down, right down, right, right up, up, and left up to get an image from the middle of your sample. Correct? I do not have a code example, but a conceptual comment.
Fixed spatial images normally start their addressing at upper left for 0,0. Because of their even numbers of pixels approach, it's near-impossible to find a "middle". So finding a "middle pixel" means you need to apply a percentage and choose the nearest "whole pixel" to the choice. Then expand to your 3x3 dimensions.
I do really recommend using numpy, when working with multidimensional arrays/when you want to manipulate these arrays, but here you go, a numpy solution and a solution without numpy.