matterport / Mask_RCNN

Mask R-CNN for object detection and instance segmentation on Keras and TensorFlow
Other
24.63k stars 11.7k forks source link

change the color #895

Open amin3511 opened 6 years ago

amin3511 commented 6 years ago

hi everybody i used demo.ipynb and When I run the program, the image that the output shows each time with a different and random color, for example, indicates the person in the image once in blue and again in violet. I want to display the same image every time in the program, for example, a person with a constant color and the colors are not random.That is, all dogs are shown with a specific color. All cats with a color and ... Can anyone help me?

fastlater commented 6 years ago

check the display_instances in visualize.py. Just set a specific color for a specific class object detected

arthurPrvst commented 6 years ago

You can get your class id in class_ids[i] and use apre-defined color. This takes place indisplay_instancesin visualize.py. To note that you can give an array of colors to display_instances function.

amin3511 commented 6 years ago

@fastlater ,@arthurPrvst Thanks for your guidance please say i shoude be done what exactly for this

arthurPrvst commented 6 years ago

@amin3511 , you have to know which class_id correpond to which object. If person class has a class_id of 1, dog classe has a class_id of 2 you can display them like this : Add this code after if show_mask: in display_instances function in visualize.pyline 156 :

if class_id == 1: 
masked_image = apply_mask(masked_image, mask, [1, 0, 0], alpha=1)
elif class_id == 2:
masked_image = apply_mask(masked_image, mask, [0, 1, 0], alpha=1)
else
masked_image = apply_mask(masked_image, mask, [0, 0, 1], alpha=1)

It will display persons in red, dogs in green and cats in blue.

amin3511 commented 6 years ago

@arthurPrvst , i added this code after if show_mask:

Mask

    mask = masks[:, :, i]
    if show_mask:
        masked_image = apply_mask(masked_image, mask, color

    # Mask Polygon
 if class_id == 1:
        masked_image = apply_mask(masked_image, mask, [1, 0, 0], alpha=1)
 elif class_id == 2:
        masked_image = apply_mask(masked_image, mask, [0, 1, 0], alpha=1)
 else
     masked_image = apply_mask(masked_image, mask, [0, 0, 1], alpha=1)

but when i run the code i get this error Traceback (most recent call last):

File "/home/ubuntu/anaconda3/envs/MaskRCNN/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2963, in run_code exec(code_obj, self.user_global_ns, self.user_ns)

File "", line 17, in from mrcnn import visualize

File "/home/ubuntu/Downloads/Mask_RCNN/mrcnn/visualize.py", line 157 if class_ids == 1: ^ SyntaxError: invalid syntax

arthurPrvst commented 6 years ago

Remove first line after if show_mask, and put all the code in the if block.

amin3511 commented 6 years ago

Thanks @arthurPrvst for your guidance Just another question how can i know which class_id correpond to which object?

padmaksha18 commented 5 years ago

@arthurPrvst
HI Arthur, I am using the matterport code for an use case where i am generating masks to blur personal details in images like faces, car no plate etc. The masks generated are very transparent and hence nothing gets blurred actually. I tried changing the code in visualize.py for each of the brightness and saturation values. def random_colors(N, bright=True): """ Generate random colors. To get visually distinct colors, generate them in HSV space then convert to RGB. """ brightness = 1.0 if bright else 0.7 hsv = [(i / N, 1, brightness) for i in range(N)] colors = list(map(lambda c: colorsys.hsv_to_rgb(*c), hsv)) random.shuffle(colors) return colors

But if i change the brightness to 0 or 1 , it either becomes dark or white but the density of color donot change. How can i achieve a complete opaque color, kindly advice. Many thanks in advance.

nkshelby commented 4 years ago

@arthurPrvst HI Arthur, I am using the matterport code for an use case where i am generating masks to blur personal details in images like faces, car no plate etc. The masks generated are very transparent and hence nothing gets blurred actually. I tried changing the code in visualize.py for each of the brightness and saturation values. def random_colors(N, bright=True): """ Generate random colors. To get visually distinct colors, generate them in HSV space then convert to RGB. """ brightness = 1.0 if bright else 0.7 hsv = [(i / N, 1, brightness) for i in range(N)] colors = list(map(lambda c: colorsys.hsv_to_rgb(*c), hsv)) random.shuffle(colors) return colors

But if i change the brightness to 0 or 1 , it either becomes dark or white but the density of color donot change. How can i achieve a complete opaque color, kindly advice. Many thanks in advance.

Hi @padmaksha18 go to visualize.py and change your 'if show_mask:' statement in display_instances function to:

if show_mask: if class_id == 1: mask_image = apply_mask(masked_image,mask,[1,0,0],alpha=1) if class_id == 2: mask_image = apply_mask(masked_image,mask,[0,1,0],alpha=1) if class_id == 3: mask_image = apply_mask(masked_image,mask,[0,0,1],alpha=1)

class 1 will be masked as RED, class 2 will be masked as GREEN, & Class 3 will be marked as BLUE. But for Opaqueness be sure to assign '1' to alpha in "apply_mask".

Hope it solves your problem.

kimile599 commented 3 years ago

@arthurPrvst HI Arthur, I am using the matterport code for an use case where i am generating masks to blur personal details in images like faces, car no plate etc. The masks generated are very transparent and hence nothing gets blurred actually. I tried changing the code in visualize.py for each of the brightness and saturation values. def random_colors(N, bright=True): """ Generate random colors. To get visually distinct colors, generate them in HSV space then convert to RGB. """ brightness = 1.0 if bright else 0.7 hsv = [(i / N, 1, brightness) for i in range(N)] colors = list(map(lambda c: colorsys.hsv_to_rgb(*c), hsv)) random.shuffle(colors) return colors But if i change the brightness to 0 or 1 , it either becomes dark or white but the density of color donot change. How can i achieve a complete opaque color, kindly advice. Many thanks in advance.

Hi @padmaksha18 go to visualize.py and change your 'if show_mask:' statement in display_instances function to:

if show_mask: if class_id == 1: mask_image = apply_mask(masked_image,mask,[1,0,0],alpha=1) if class_id == 2: mask_image = apply_mask(masked_image,mask,[0,1,0],alpha=1) if class_id == 3: mask_image = apply_mask(masked_image,mask,[0,0,1],alpha=1)

class 1 will be masked as RED, class 2 will be masked as GREEN, & Class 3 will be marked as BLUE. But for Opaqueness be sure to assign '1' to alpha in "apply_mask".

Hope it solves your problem.

Hi bro,

You know how to change the score and class id in the instance.

微信截图_20201206175129

like the score in this fig. It is white and hard to read. So i change the display_instance in line 138-147 in visulaize.py

    # Label
    if not captions:
        class_id = class_ids[i]
        score = scores[i] if scores is not None else None
        label = class_names[class_id]
        caption = "{} {:.3f}".format(label, score) if score else label
    else:
        caption = captions[i]
    ax.text(x1, y1 + 8, caption,
            color='b', size=110, backgroundcolor="w")

I change the color=‘w’ to 'b'. Just nothing changes.