-1

I am getting mask image and RGB image from Unreal Engine using UnrealCV. Here, I also get the color information(R, G, B) of the object using UnrealCV from the mask image. Now, I want to know how can I pass this RGB information to OpenCV to do the thresholding.

I am doing now this stuff converting the mask image to Grayscale image and then doing the thresholding. But I don't want to do this. I have checked this answer but here image range has used which I also don't want to do. As in the mask image, every object has its unique color information so I just want to be more specific by sending the RGB information of the desired object from the mask image and then want to tell OpenCV to do the thresholding on the color that I have sent to OpenCV thresholding function.

The code used to get the RGB information is --

get_mask_color= client.request('vget /object/object_name/color')

It will give the mask color and then I want to pass it to OpenCV for the thresholding purpose.

I expect that it will do the thresholding as like as it is now doing on Grayscale image and then I will use the thresholded image to do the contour operation.

user10634362
  • 549
  • 5
  • 21
  • 1
    Your question is extremely hard to understand. It might help if you showed the shape and contents of your mask image, the shape and contents of the image you want to threshold and what you expect the result to be. – Mark Setchell Jun 06 '19 at 12:11
  • OK, @MarkSetchell. [this is one of the mask images](https://i.imgur.com/YvL7cwa.png) while the [RGB](https://i.imgur.com/EUIQfV6.png) is this. I am getting the RGB info of the square box from the mask image using the mentioned UnrealCv command. Now I want to pass the RGB info to the Thresholding function of OpenCV. That's all. I just want to know the procedure of passing the RGB info to do the thresholding. I am repeating again I don't want to convert my mask image to GRAYscale image or into any other format. – user10634362 Jun 06 '19 at 12:29
  • I still don't understand. There appear to be 3 colours in your mask - black, peach and lilac. And there's a picture of some dishwasher tablets on a slope with the sky as a background. What is supposed to happen next? And why don't you want to use any greyscale? – Mark Setchell Jun 06 '19 at 13:06
  • Ahh Ok, I am clearing the view. There 3 contours will not come. I know the name of the square box from Unreal Engine. So, I will use the name to get the color info and it is completely unique. look at this command ```get_mask_color= client.request('vget /object/object_name/color') ``` It will only give me the color of the square box. Then I want to convey this RGB value to do the thresholding. I don't want to use grayscale as sometimes from mask image after converting to gray color my desired object mixed with the background then it is difficult to do thresholding > finding contour. – user10634362 Jun 06 '19 at 13:10
  • It's unclear why it's important that you know the name of the box, why it's important that it came from Unreal Engine and why it's important that something is unique. What are you trying to do? Can you make a simple sentence please? *"Everywhere the mask is black, I want to do XYZ. Everywhere the mask is peach-coloured, I want to do ABC..."* – Mark Setchell Jun 06 '19 at 21:13

1 Answers1

0

In a grayscale image, thresholding separates dark from light pixels, i.e. splits the gray range in two subintervals. This is based on the (naive) premise that the object of interest is made of the lightest (or darkest) colors.

A slightly more logical approach is to consider the pixel values inside a subinterval defined by two thresholds (average color ± max variation). If the object of interest has several distinct colors, each corresponds to an interval of gray values, and these will overlap or not. In practice, this works poorly because many other features in the scene can have the same gray levels.

In the case of color, things are more complicated. A uniform color defines a single point in RGB space, and when you take the variations into account, you observe a whole volume, with a certain shape. If you are lucky, the shape is an compact ellipsoid; if there are shading and/or shadow effects, the shape can be cone-like and more extended.

Again, when the object is made of several colors, the volume can be made of several overlapping or isolated shapes.

To handle a given application, you have to understand the shape of the RGB cloud corresponding to your object, and find a suitable geometric description. As a very first approximation, you can use a cube or sphere, with given center and extent.