Here, I have python code which is helping me in selecting 5 by 5 window from upper left corner of a raster (.tif). I want a process to automate through entire image in 5 by 5 convolution window.

import cv2
import numpy as np
from matplotlib import pyplot as plt 
img = cv2.imread('class.tif')
kernel = np.ones((5,5),np.float32)

How to loop the kernel which will cover all pixels from a raster in 5 by 5 convolution window for getting all pixel values in this convolution window? I don't want to generate another raster. I want location of abnormal values within each window after statistical tests. How is it possible?

  • In a deleted former commentary you said: "I don't want to convert raster to an array..." but, I guess that you want all raster values in a 5x5 window from upper left corner of a raster (.tif) through entire image in 5x 5 window. I would like to know how will you accomplish this if you don't want to read raster values first. – xunilk Jan 13 '18 at 1:26
  • Sir, may be I am wrong but using "cv2" module I am able to read an image without converting it into an array . It is reading pixel values only. So I thought if someone has idea to modify it further and serve the purpose. Further, I don't mind in converting raster to an array but ultimately I need lat-lon of highlighted pixels . If you it is possible even after converting it into an array then I would happy to do that. @xunilk – vigna purohit Jan 13 '18 at 4:36
  • I voted this question for reopening but, why did you choose this cv2 python module? Did you read its documentation? If you print 'img', you will see that it is a very strange array (yes, an ARRAY!). If you had read the documentation, you would have seen the need to use flags for a good use of 'imread' method. – xunilk Jan 17 '18 at 13:39
  • I found out because you chose this amazing python module named cv2. I also found out how to loop the kernel for covering all pixels from a raster in 5 by 5 convolution window. – xunilk Jan 17 '18 at 22:55
  • Thank you for reopening sir. As i said I am not a python pro but I have to use it as I want automation in my thesis work. Yes, I had read the documentation and I found worth trying it. If you have better option suggest any other module to complete this task. Previously I was working with GDAL and nupy for all raster operations should I continue with it? @xunilk – vigna purohit Jan 18 '18 at 6:51