Forum

Author Topic: Automatic mask generation?  (Read 11236 times)

7eicher

  • Newbie
  • *
  • Posts: 42
    • View Profile
Automatic mask generation?
« on: September 09, 2013, 11:39:21 AM »
Dear folks,

i wonder if anyone tried yet to autogenerating masks. In my case I treat lots of high reso images (> 500) by hand to mask the sky out. Taking lots of time, little bit annyoing :)

So does anyone or does you guys from Agisoft has a semi-automated solution for that?

When I think of that task as a developer I would let the user (me) pick a color and tolerance, than search in the image for lets say larger areas of this color and similar color (tolerance), like the magic picker function does. Than append that area to the mask. Hence save. Afterwards the user needs to check each image, which should be easy, by looking at the mask-preview in the photo area.

I would prefer a python API solution, to have controll over the process.

Any ideas? Maybe an external tool can help?

Take care,

Markus

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Automatic mask generation?
« Reply #1 on: September 09, 2013, 11:53:47 AM »
Hello Markus,

You can try the following function - it works both on background image (like Import from Background feature in GUI, but also you can input color as background argument):

Code: [Select]
function:: createDifferenceMask(image, background, tolerance=10, fit_colors=False)

Creates mask from a pair of images or an image and specified color.

:arg image: Image to be masked.
:type image: :class:`Image`
:arg background: Background image or color value.
:type background: :class:`Image` or color tuple
:arg tolerance: Tolerance value.
:type tolerance: int
:arg fit_colors: Enables white balance correction.
:type fit_colors: boolean
:return: Resulting mask.
:rtype: :class:`Image`
Best regards,
Alexey Pasumansky,
Agisoft LLC

7eicher

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: Automatic mask generation?
« Reply #2 on: September 10, 2013, 02:35:39 AM »
Dear Alexey,

thanks for your valuable feedback. I tried the following line:

mask = PhotoScan.Utils.createDifferenceMask(cam.image(), (108,145,195), 10, False)

and got a strange exception:

TypeError: descriptor 'createDifferenceMask' requires a 'PhotoScan.Utils' object but received a 'PhotoScan.Image'

What I am missing?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Automatic mask generation?
« Reply #3 on: September 10, 2013, 10:33:32 AM »
Hello 7eicher,

I think you should use  PhotoScan.utils.createDifferenceMask().
Best regards,
Alexey Pasumansky,
Agisoft LLC

7eicher

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: Automatic mask generation?
« Reply #4 on: September 10, 2013, 05:25:41 PM »
Dear Alexey,

thanks for your reply. That worked so far. So I made some tests and got a small success detecting a simple black/white colored image using this command:

img = PhotoScan.app.document.activeChunk.cameras[0].image()
PhotoScan.utils.createDifferenceMask(img, (0,0,0), 50, True).save(r"d:/tmp/test_mask.png")

The RGB tuple represents black color (0,0,0). So far so good.

Then i tried a real image (see attachment). I picked up different colors (e.g. paint) from the sky in the image and tried the same command as above but without success. I also tried to use 100 tolerance, but no success. Here are colors I tried out:

137,230,216
185,214,205
231,247,255

The result was always an empty (white) mask image.

What did I do wrong? Do I need to use another color picker, other color format?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Automatic mask generation?
« Reply #5 on: September 10, 2013, 05:39:53 PM »
Hello 7eicher,

If you are using color and not background image for difference masking you should turn off fit_colors (use False as the parameter). I think that's the problem in this case.
Best regards,
Alexey Pasumansky,
Agisoft LLC

7eicher

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: Automatic mask generation?
« Reply #6 on: September 10, 2013, 05:54:44 PM »
Great Alexey, it works.

Thanks! So now I can continue my script... :)

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Automatic mask generation?
« Reply #7 on: February 06, 2015, 02:19:31 PM »
Have posted a sample script for mask generation from user selected color with tolerance:
http://wiki.agisoft.com/wiki/Masks_From_Color.py
Best regards,
Alexey Pasumansky,
Agisoft LLC