Recent

Author Topic: Working with areas of an image  (Read 5207 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2257
    • Lazarus and Free Pascal italian community
Working with areas of an image
« on: September 04, 2016, 12:12:08 pm »
Hello guys, I wanted to ask. When I have a picture like the one attached. Let us imagine that I want to draw a green outline to one of the teeth simply by clicking on it and if I click a second time on board disappears. How should I do?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Thaddy

  • Hero Member
  • *****
  • Posts: 17157
  • Ceterum censeo Trump esse delendam
Re: Working with areas of an image
« Reply #1 on: September 04, 2016, 01:06:44 pm »
Start with studying this example:
/packages/imagemagick/examples/wanddemo.lpr
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

xinyiman

  • Hero Member
  • *****
  • Posts: 2257
    • Lazarus and Free Pascal italian community
Re: Working with areas of an image
« Reply #2 on: September 04, 2016, 01:17:12 pm »
Is a cross-platform Solutions?!
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Thaddy

  • Hero Member
  • *****
  • Posts: 17157
  • Ceterum censeo Trump esse delendam
Re: Working with areas of an image
« Reply #3 on: September 04, 2016, 01:30:21 pm »
Yes, for every platform that is supported by imagemagick (many!).
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

lainz

  • Hero Member
  • *****
  • Posts: 4723
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Working with areas of an image
« Reply #4 on: September 04, 2016, 03:22:09 pm »
LazPaint also comes with a magic wand tool, you can start here:
https://github.com/bgrabitmap/lazpaint/blob/master/lazpaint/utoolselect.pas#L34

Seems that uses the function ParallelFloodFill of BGRABitmap:
Code: Pascal  [Select][+][-]
  1. Manager.Image.SelectedImageLayerReadOnly.ParallelFloodFill(pt.X,pt.Y,toolDest,penColor,fmDrawWithTransparency,Manager.ToolTolerance);

circular

  • Hero Member
  • *****
  • Posts: 4441
    • Personal webpage
Re: Working with areas of an image
« Reply #5 on: September 05, 2016, 11:35:40 am »
Indeed, what you can do is to have a second image that contains the selection. First fill it with black. Then when there is a click, check that it is within a tooth (that it is white) and then do a parallel floodfill in white on the selection image.

You can draw the highlighted selection different ways, for example by calling FillMask on the display image to give some color to the selected tooth. If instead of highlighting the tooth, you want the border of the selected tooth, you can use Contour filter on the selection or EmbossHighlight filter.
Conscience is the debugger of the mind

Thaddy

  • Hero Member
  • *****
  • Posts: 17157
  • Ceterum censeo Trump esse delendam
Re: Working with areas of an image
« Reply #6 on: September 05, 2016, 12:59:18 pm »
Since that is a solution that is written completely in Object Pascal, I actually like that more than imagemagick ;)
You may even try to Black-out all teeth and combine all but the one that needs to disappear. Kind of layers (actually: then you would use layers)
Well done Circular!
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

 

TinyPortal © 2005-2018