Getting the original pixel value in a thresholded RGB image

asked 2020-05-03 11:05:01 -0600

titli gravatar image

updated 2020-05-04 04:04:55 -0600

supra56 gravatar image
  • I have an RGB image and also depth values per pixel in a text file
    • I formed depth image and done thresholding.
    • Now I want the original color of thee RGB image in the threshold part.
    • What I feel is, I need to get the position of the black pixels and then create a full white pixel image and then will map the rgb values in the original image corresponding to the previously determined black pixel position into that white image.

I have coded this far:

import cv2
import numpy as np

depth_image = np.loadtxt(fname = "D:/workspace/1.txt", delimiter=',', skiprows=0)
print(depth_image.shape)
rgb = cv2.imread("D:/workspace/1.jpg")
print(rgb.shape)
gray =  cv2.cvtColor(rgb, cv2.COLOR_BGR2GRAY)
out = np.zeros(depth_image.shape, np.double)
#normalized = cv2.normalize(depth_image, out, 1.0, 0.0, cv2.NORM_MINMAX, dtype=cv2.CV_64F)
norm_image = cv2.normalize(depth_image, None, alpha=0, beta=1, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_32F)
#print(norm_image)
mask = norm_image < 0.1

sel = np.zeros_like(depth_image)
colored = np.zeros_like(rgb)
sel[mask] = depth_image[mask]
sel_not = 255-sel

#print(sel_not)
'''indices = np.where(sel_not == [10])
print (indices)
coordinates = zip(indices[0], indices[1])
print (coordinates)'''

cv2.imshow('display',sel_not)
#cv2.imshow('thresholded',colored)

cv2.waitKey(0)

Image used is: image description

Link to my depth information file

edit retag flag offensive close merge delete