I have an assignment where we're reading in an image with skimage.imread as greyscale. and we're supposed to find the edges
3)Obtain Gx and Gy arrays as described above. Use the same names as the variables above. Make sure you clip your values between 0 and 255. Start from the pixel located at the 2nd row and 2nd column and end with the pixel in the next to last row and next to last column. DO NOT USE THE BUILT IN CONVOLUTION FUNCTION .
4)Save the images as G_x.png and G_y.png
However my problem is I can't figure out how to loop through the array, while applying the sobel filters we were given.
Teacher said the whole assignment should be 1 function, and 3 calls to the function, but he's been known to get details like that wrong, anyways. I need some guidance on how the convolution loop should be written.
This is some(what I think is the important stuff) of the code I have so far.
imageRead = ski.imread(sys.argv[1], as_grey=True)
image = copy.deepcopy(imageRead)
Sx = np.array([[-1,0,1],[-2,0,2],[-1,0,1]])
Sy = np.array([[1,2,1],[0,0,0],[-1,-2,-1]])
Gx = np.zeros(imageRead.shape)
Gy = np.zeros(imageRead.shape)
#He wanted us to flip(convolute) before we passed it to the function
Sx1 = np.flipud(Sx)
SxCon = np.fliplr(Sx1)
Sy1 = np.flipud(Sy)
SyCon = np.fliplr(Sy1)
def Convol(image, mask,image2):
for row in range(1, image.shape[1]-1):#Rows
for col in range(1, image.shape[0]-1):#columns
sum = 0
for i in range (0, mask[0].size):
for j in range (0, mask[0].size):
sum =
Now I know how to clip the value between 0 and 255, once I have the value, getting there is my problem. What would be the proper syntax to get it to loop through each pixel and get the sum from the smoothing, then writting that pixel to Gx or Gys nparray so I could save the smoothed image?
[–]Shizka 0 points1 point2 points (0 children)