1

I have 75 photos of a "light section", and I thresholded the pictures.

original image

threshold image

Now, I want to make those thresholds smoother and thinner because I will use them to calculate a point cloud. I don't know how to make them thinner, smoother, and more accurate. I am new at this topic, therefore I will be grateful if you help me.

Here is the code for thresholds:

import cv2
import numpy as np
import os
from os import path

count = len(os.listdir(r'C:\Users\MERYEM\Desktop\scan\Chosen'))
print(count)
path = r'C:\Users\MERYEM\Desktop\scan\Chosen'
new_path = r'C:\Users\MERYEM\Desktop\scan\threshold_images'

for i in range(1,count+1) :
    image = cv2.imread(str(path)+"\{0}.jpg".format(i))
    grayscaled = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
    retval2, threshold2 = cv2.threshold(grayscaled,58,255,cv2.THRESH_BINARY)
    result=cv2.imwrite(str(new_path)+"\{0}.jpg".format(i), threshold2)
    if result==True:
        print("File saved successfully")
    else:
        print("Error in saving file")

    cv2.waitKey(0)
    cv2.destroyAllWindows()
Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
  • I think your best bet is to find the ridges of the original image, instead of thresholding. But please clarify your post: what does “use in the point cloud” mean? What are these images of? These details help in understanding the problem and guide you to a better solution. – Cris Luengo Oct 08 '21 at 13:46
  • Welcome to Stack Overflow! I would suggest looking into Mathematical Morphology operations including "closing" (to fill in small holes in the white areas) and "thinning" or "skeletonizing", to reduce the white areas to their "skeletons". – Mark Lavin Oct 08 '21 at 13:47
  • Hello @CrisLuengo, I am trying to create point cloud of laser-scanned objects. Therefore, firstly I took the thresholds of the images that I've scanned. After that, I thought that those images are not quite good to create a good point cloud. Now, I'm thinking about how to make those images much thinner and smoother. – Meryem Çiftçi Oct 08 '21 at 15:28
  • ignore recommendations to use morphology operations. those won't fix up the bad thresholding. your picture is **saturated** (the red channel certainly is bleeding into green and blue, as evidenced by the laser lines becoming white), which is bad. you need to threshold a lot closer to white, and potentially even cvtColor to HSV and inRange in that space. and the next pictures you take need to be taken with less exposure (shorter exposure time or narrower aperture) – Christoph Rackwitz Oct 08 '21 at 16:54
  • 1
    a fixed threshold of 128 (on the grayscale version of the image) would already give you a usable result... I don't know why you'd even bother with adaptive thresholds. you can fix and adjust your camera settings and be done with it. – Christoph Rackwitz Oct 08 '21 at 17:02

0 Answers0