Get masked image


In previous tutorial, we got object mask image of red box, and the next step is masking the color image using it. We shows how to apply mask image to color image in this tutorial.

Step by step

First, you need image topic, so please run tutorial_image_publisher.launch in previous tutorials: Publish staic image topic, Find object with color filtering, and below rostopic list output is expected:

$ rostopic list

For this purpose, we can use apply_mask_image. The advance from previous tutorials is it subscribes 2 topics: color image and mask for processing.

$ rosrun jsk_perception apply_mask_image
    _clip:=false _approximate_sync:=false _queue_size:=100 \
    \~input:=image_publisher/output \~input/mask:=hsv_color_filter/image

_clip:=false is for disabling cropping of the region. _approximate_sync:=false and _queue_size:=... is for synchronization method of timestamp, that is needed if you subscribes multiple topics. In this case, the both topic has the exactly the same stamp and it can be synchronized without approximation. You can see the timestamp by below:

$ rostopic echo /image_publisher/image/header/stamp
$ rostopic echo /hsv_color_filter/image/header/stamp

The result will be like below:


Get better results

To get better results, you need some processing to the mask, and below launch file includes the program:

Or you can download the file from:


  <node name="apply_mask_image"
        pkg="jsk_perception" type="apply_mask_image">
    <remap from="~input" to="image_publisher/output" />
    <remap from="~input/mask" to="hsv_color_filter/image" />
      clip: false

  <node name="image_view_apply_mask"
        pkg="image_view" type="image_view">
    <remap from="image" to="apply_mask_image/output" />

  <!-- !!! ADVACED !!!! -->

  <node name="bounding_object_mask_image"
        pkg="jsk_perception" type="bounding_object_mask_image">
    <remap from="~input" to="hsv_color_filter/image" />

  <node name="apply_mask_image_better"
        pkg="jsk_perception" type="apply_mask_image">
    <remap from="~input" to="image_publisher/output" />
    <remap from="~input/mask" to="bounding_object_mask_image/output" />
      clip: false

  <node name="image_view_apply_mask_better"
        pkg="image_view" type="image_view">
    <remap from="image" to="apply_mask_image_better/output" />


You can launch the roslaunch file by:

$ roslaunch ./tutorial_get_masked_image.launch

The result will be like below: