Skip to main content
Code Review

Return to Question

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

I have another question question from same program where is full code, but this question focus only single process/function of that program.

I have another question from same program where is full code, but this question focus only single process/function of that program.

I have another question from same program where is full code, but this question focus only single process/function of that program.

I think it's okay to be here
Source Link
Evus
  • 205
  • 2
  • 12

First of all, if this question belongs to Stackoverflow. Mention about it.

I have another question from same program where is full code, but this question focus only single process/function of that program.

First of all, if this question belongs to Stackoverflow. Mention about it.

I have another question from same program where is full code, but this question focus only single process/function of that program.

I have another question from same program where is full code, but this question focus only single process/function of that program.

added 2 characters in body
Source Link
Evus
  • 205
  • 2
  • 12
 def getKernels(self, pixels, width):
 kernels = []
 pixels = [x for sublist in pixels for x in sublist] #2D list to 1D
 for i in range(0,len(pixels)):
 tx = (i % width) #Calc pixel x-cordinate
 ty = math.floor(i / width) #Calc y-cordinate
 kernel = []
 for y, x in pngself.kernelGenerator(ty,tx,3): #Pass current pixel index cordinates and size of kernel
 try:
 index = (x)+((y)*width) #Calc index 
 if index > -1 and index < len(pixels): #Check that index is in list bounds
 kernel.append(pixels[index])
 else: #Out of list bounds make pixel black
 kernel.append(0)
 except Exception as e:
 raise e
 kernels.append(kernel)
 return kernels
 def kernelGenerator(self, x, y, size):
 if size % 2 == 0 or size < 3: #Because pixel has to be "center" of my kernel
 print("Kernel size should be odd and greater than 2")
 raise
 kernel = []
 for i in range(math.ceil(-size/2),math.ceil(size/2)):
 for j in range(math.ceil(-size/2),math.ceil(size/2)):
 kernel.append((x+i,y+j))
 return kernel
 def getKernels(self, pixels):
 kernels = []
 for ty, row in enumerate(pixels): #get pixel Y-cordinate and row
 for tx, px in enumerate(row): #get pixel X-cordinate and px
 kernel = []
 for y, x in pngself.kernelGenerator(ty,tx,3):
 try:
 kernel.append(pixels[y][x])
 except Exception as e:
 kernel.append(0)
 kernels.append(kernel)
 return kernels
 def kernelGenerator(self, x, y, size):
 if size % 2 == 0 or size < 3: #Because pixel has to be "center" of my kernel
 print("Kernel size should be odd and greater than 2")
 raise
 kernel = []
 for i in range(math.ceil(-size/2),math.ceil(size/2)):
 for j in range(math.ceil(-size/2),math.ceil(size/2)):
 kernel.append((x+i,y+j))
 return kernel
 def getKernels(self, pixels, width):
 kernels = []
 pixels = [x for sublist in pixels for x in sublist] #2D list to 1D
 for i in range(0,len(pixels)):
 tx = (i % width) #Calc pixel x-cordinate
 ty = math.floor(i / width) #Calc y-cordinate
 kernel = []
 for y, x in png.kernelGenerator(ty,tx,3): #Pass current pixel index cordinates and size of kernel
 try:
 index = (x)+((y)*width) #Calc index 
 if index > -1 and index < len(pixels): #Check that index is in list bounds
 kernel.append(pixels[index])
 else: #Out of list bounds make pixel black
 kernel.append(0)
 except Exception as e:
 raise e
 kernels.append(kernel)
 return kernels
 def kernelGenerator(self, x, y, size):
 if size % 2 == 0 or size < 3: #Because pixel has to be "center" of my kernel
 print("Kernel size should be odd and greater than 2")
 raise
 kernel = []
 for i in range(math.ceil(-size/2),math.ceil(size/2)):
 for j in range(math.ceil(-size/2),math.ceil(size/2)):
 kernel.append((x+i,y+j))
 return kernel
 def getKernels(self, pixels):
 kernels = []
 for ty, row in enumerate(pixels): #get pixel Y-cordinate and row
 for tx, px in enumerate(row): #get pixel X-cordinate and px
 kernel = []
 for y, x in png.kernelGenerator(ty,tx,3):
 try:
 kernel.append(pixels[y][x])
 except Exception as e:
 kernel.append(0)
 kernels.append(kernel)
 return kernels
 def kernelGenerator(self, x, y, size):
 if size % 2 == 0 or size < 3: #Because pixel has to be "center" of my kernel
 print("Kernel size should be odd and greater than 2")
 raise
 kernel = []
 for i in range(math.ceil(-size/2),math.ceil(size/2)):
 for j in range(math.ceil(-size/2),math.ceil(size/2)):
 kernel.append((x+i,y+j))
 return kernel
 def getKernels(self, pixels, width):
 kernels = []
 pixels = [x for sublist in pixels for x in sublist] #2D list to 1D
 for i in range(0,len(pixels)):
 tx = (i % width) #Calc pixel x-cordinate
 ty = math.floor(i / width) #Calc y-cordinate
 kernel = []
 for y, x in self.kernelGenerator(ty,tx,3): #Pass current pixel index cordinates and size of kernel
 try:
 index = (x)+((y)*width) #Calc index 
 if index > -1 and index < len(pixels): #Check that index is in list bounds
 kernel.append(pixels[index])
 else: #Out of list bounds make pixel black
 kernel.append(0)
 except Exception as e:
 raise e
 kernels.append(kernel)
 return kernels
 def kernelGenerator(self, x, y, size):
 if size % 2 == 0 or size < 3: #Because pixel has to be "center" of my kernel
 print("Kernel size should be odd and greater than 2")
 raise
 kernel = []
 for i in range(math.ceil(-size/2),math.ceil(size/2)):
 for j in range(math.ceil(-size/2),math.ceil(size/2)):
 kernel.append((x+i,y+j))
 return kernel
 def getKernels(self, pixels):
 kernels = []
 for ty, row in enumerate(pixels): #get pixel Y-cordinate and row
 for tx, px in enumerate(row): #get pixel X-cordinate and px
 kernel = []
 for y, x in self.kernelGenerator(ty,tx,3):
 try:
 kernel.append(pixels[y][x])
 except Exception as e:
 kernel.append(0)
 kernels.append(kernel)
 return kernels
 def kernelGenerator(self, x, y, size):
 if size % 2 == 0 or size < 3: #Because pixel has to be "center" of my kernel
 print("Kernel size should be odd and greater than 2")
 raise
 kernel = []
 for i in range(math.ceil(-size/2),math.ceil(size/2)):
 for j in range(math.ceil(-size/2),math.ceil(size/2)):
 kernel.append((x+i,y+j))
 return kernel
Added third approach. Hope it is Ok.
Source Link
Evus
  • 205
  • 2
  • 12
Loading
added 7 characters in body
Source Link
Evus
  • 205
  • 2
  • 12
Loading
Source Link
Evus
  • 205
  • 2
  • 12
Loading
lang-py

AltStyle によって変換されたページ (->オリジナル) /