Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
291 views
in Technique[技术] by (71.8m points)

python - How to do Colour Image Segmentation on a Depth map AND Create an 9 Indicie Array Representing the Results?

What is my issue?

I am working on a project that takes an image as an input which is then converted into a depth map using DenseDepth then I want to create a mask of this depth map by taking a colour range and then generating a mask, this data is then stored into an array by splitting the mask up into an even grid of nine and if it contains over 50% masked area (black) then it is saved as a 1 in the array otherwise it is saved as a 0. I have put together a small illustration below to better explain what I would like to achieve. Where I have labelled completed this is what I have already done. As this is my first question I cannot embed an image directly so I have linked it below!

Illustration explaining my issues and what I want to achieve clearly

How have I tried to solve this?

Here is an article that I followed on Image segmentation to try to create the mask, however, I'm sure it can be improved here - this is in Spanish (I think) but on Chrome it auto-translates

Here is my code for the masking:

import cv2
import numpy as np

image = cv2.imread('Depth Map 1.png')
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
blur = cv2.medianBlur(hsv ,11)

lower = np.array([0,0,35])
upper = np.array([0,0,44])

mask = cv2.inRange(blur, lower, upper)
res = cv2.bitwise_and(image,image, mask= mask)            

cv2.imshow("mask ",mask)
cv2.imshow('stack', np.hstack([image, res]))
cv2.waitKey(0)

To find the upper and lower values I ran this code - press R to get the values.

As for dividing the masked image into a grid and then creating an 9 bit array based of this, I am completely at a loss.

If anyone is interested I generated the depth map using DenseDepth and then adjusted it to fit my needs ie. create a grey map instead and output multiple single images.

If there is any extra information that I may have left out or things that could help you help me solve the issue then I will definitely try to help

For testing purposes I have included some depth maps that I have generated:

Depth Map 1

Depth Map 2

Depth Map 3

Depth Map 4

EDITS In the code I have adjusted '6.png' to 'Depth Map 1.png' to make this clearer.

I have realised that this question would be better suited split of into two separate questions. Which I have/am asking.

Here is the first one:

How to mask a Depth Map to select grey values in-between two specified hex-codes?

However, help here would definitely still be appreciated!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...