Pixel image detection in python

I am trying to determine if an image has a square (pixelated).

I heard about the Fourrier two-dimensional transform with numpy or scipy, but it's a little complicated.

The goal is to determine the number of squares of a zone due to poor compression like this (img a):

+4
source share
2 answers

I have no idea if this will work, but you can try to find the nearest neighbors around the pixel. The pixel squares will be a visible jump in the RGB values โ€‹โ€‹around the area.

You can find the nearest neighbors for each pixel in the image with something like

def get_neighbors(x,y, img): ops = [-1, 0, +1] pixels = [] for opy in ops: for opx in ops: try: pixels.append(img[x+opx][y+opy]) except: pass return pixels 

This will give you the closest pixels in the area of โ€‹โ€‹the source image.

To use it, you would do something like

 def detect_pixellated(fp): img = misc.imread(fp) width, height = np.shape(img)[0:2] # Pixel change to detect edge threshold = 20 for x in range(width): for y in range(height): neighbors = get_neighbors(x, y, img) # Neighbors come in this order: # 6 7 8 # 3 4 5 # 0 1 2 center = neighbor[4] del neighbor[4] for neighbor in neighbors: diffs = map(operator.abs, map(operator.sub, neighbor, center)) possibleEdge = all(diff > threshold for diff in diffs) 

After further thought, use OpenCV and perform edge detection and get the outline dimensions. It will be much simpler and more reliable.

+2
source

If you look at its lines, it is easier, because then you are dealing with line graphs instead of 2d graphs of images, which is always easier.

Decision:

scan the string by pixels, put the string in an array if it is faster for computation, and then run the algorithms in the string (s) to determine the degree of blocking:

1 / skip each pixel in your line and compare it with the previous pixel, subtracting the value between the two pixels. create an array of previous pixel values. if large jumps in pixel values โ€‹โ€‹are at regular inverse values, this blocks. if there are large jumps in values โ€‹โ€‹combined with small jumps in values, they block ... you can assume that if there are many identical differences in pixels, this will block, especially if you repeat the analysis twice at intervals between two and four adjacent pixels and on several lines.

You can also create graphs of the differences between pixels between pixels 3-5-10 pixels apart to have additional information about the gradient changes of sample lines of images. if the ratio of differences in pixels of neighboring pixels to fifth neighboring pixels is similar, it also indicates non-smooth colors.

there can be many algorithms, including a fast four on a line graph, the same as the sound you would use on the line (s) from the figure, which is simpler than the 2d image algorithm.

+1
source

All Articles