Home>

I want to make a contour image from a depth image,
1. Convert a depth image into an image consisting of small blocks of 4 * 4 pixels
Find the maximum and minimum values ​​of the depth values ​​of 2, 4 * 4 pixels
3. If the obtained difference is larger than the threshold value, it is determined that all the pixels in the small block are contour lines.
I would like to guide the image by the procedure.

I was able to read the image and paint 4 * 4 pixels with the same color as one block to make a low-resolution image, but I'm not sure where to read the pixel value from there and decide the judgment.

The following program is the program used when seeking a low resolution image.
I would like to change this partly to create a contour image.

Corresponding source code
import numpy as np
import matplotlib.pyplot as plt
import cv2
from skimage import io
img_orig = io.imread ('IMG_0072.jpeg')
plt.imshow (img_orig)
plt.show ()
def pool_max (img, ksize_h = 16, ksize_w = 16):
    _img = img.copy (). astype (np.float32)
    # padding
    h, w = img.shape [: 2]
    outer_h = h% ksize_h
    pad_top = outer_h // 2
    pad_bottom = outer_h --pad_top
    outer_w = w% ksize_w
    pad_left = outer_w // 2
    pad_right = outer_w --pad_left
    _img = np.pad (_img, [(pad_top, pad_bottom), (pad_left, pad_right), (0, 0)],'edge')
    out = np.zeros_like (_img)
    new_h, new_w = out.shape [: 2]
    c = 1 if len (out.shape) == 2 else out.shape [2]
    #filtering
    for iy in range (0, new_h, ksize_h):
        for ix in range (0, new_w, ksize_w):
            for ic in range (c):
                out [iy: iy + ksize_h, ix: ix + ksize_w, ic] = _img [iy: iy + ksize_h, ix: ix + ksize_w, ic] .max ()
    out = out [pad_top: pad_top + h, pad_left: pad_left + w]
    return np.clip (out, 0, 255) .astype (np.uint8)
img_pool = pool_max (img_orig) #pooling
plt.figure (figsize = (12, 3))
plt.subplot (1, 2, 1)
plt.title ('input')
plt.imshow (img_orig)
plt.subplot (1, 2, 2)
plt.title ('answer')
plt.imshow (img_pool)
plt.show ()