Log in

View Full Version : Image enhancement using watershed technique


vcmohan
31st October 2006, 12:56
I have recently authored two plugins using Segmentation by watershed algorithm.

SegmentedAmp plugin smooths image within the basin boundaries and also accentuates the boundaries. By preprocessing the image to reduce over_segmentation, image can be enhanced.

ReTouch plugin in addition to segmentation uses flood fill technique to stretch image values within the basin boundaries or shifts or replaces by the lowest or highest value within each basin.
I have used an image which appeared in one of the threads and didee wove a magic spell around it. http://forum.doom9.org/showthread.php?t=115181

The result from using segmentedAmp are :
http://img307.imageshack.us/img307/3528/segmentedamp0df5.th.jpg (http://img307.imageshack.us/my.php?image=segmentedamp0df5.jpg)
Top row are inputs with various preprocessing plugins.
Result with ReTouch is :
http://img415.imageshack.us/img415/7310/retouch0gh0.th.jpg (http://img415.imageshack.us/my.php?image=retouch0gh0.jpg)
On right is processed using retouch and other plugins.
Only spatial processing has been done.
More details are at my plugin page.

unskinnyboy
31st October 2006, 13:06
Could you also tag each image with how it was processed and using what parameters, maybe using the subtitle() function? It is much easier to compare that way.

G_M_C
31st October 2006, 14:14
I have recently authored two plugins using Segmentation by watershed algorithm.

SegmentedAmp plugin smooths image within the basin boundaries and also accentuates the boundaries. By preprocessing the image to reduce over_segmentation, image can be enhanced.

ReTouch plugin in addition to segmentation uses flood fill technique to stretch image values within the basin boundaries or shifts or replaces by the lowest or highest value within each basin.
[...]


:o

Hmmm, I try to understand what your explination actually means, but im at a loss. May I ask for some some extra info/explination (read this as a request for a noob-translation :D )

foxyshadis
31st October 2006, 19:45
Both plugins are still 404 on the site. ;) So I'm recompiling from source in the meantime.

I'm looking at this as another way to implement clouded's cel-foreground idea, which is boss.

Pookie
31st October 2006, 20:03
Foxyshadis -

http://www.avisynth.org/vcmohan/ReTouch/ReTouch.zip

http://www.avisynth.org/vcmohan/SegmentedAmp/SegmentedAmp.zip

vcmohan
1st November 2006, 04:39
Could you also tag each image with how it was processed and using what parameters, maybe using the subtitle() function? It is much easier to compare that way.

The script used for processing is at my plugins page. Since I used for preprocessing my other plugins, I thought it will be best to direct to my plugins page.

G_M_C wrote Hmmm, I try to understand what your explination actually means, but im at a loss. May I ask for some some extra info/explination (read this as a request for a noob-translation

I am not sure which part is to be explained more. You may kindly visit my plugins page and see the watershed, SegmentedAmp and Retouch plugins for a more detailed explanation. However simply watershed assumes the image values as elevations and based on certain criterion draws watershed lines (just as a civil engineer does on land) and numbers individual basins. Retouch and SegmentedAmp are built over this segmentation, to alter the image values.
Watershed in more detail is availble through Google search.

Fizick
1st November 2006, 05:58
vcmohan,
please replace 'ZIP' to 'zip' extention in your new web page links.

Also check (and fix) your new 'JPG' links, such as
http://www.avisynth.org/vcmohan/Reform/Reskewed2.JPG

vcmohan
1st November 2006, 08:25
Yes. Corrected. As on my windows system capitalization has no effect my testing it did not catch it. Thanks for pointing out.
Instead of downloading the dlls the writeup can be seen at
http://www.avisynth.org/vcmohan/ReTouch/ReTouch.html

http://www.avisynth.org/vcmohan/SegmentedAmp/SegmentedAmp.html

G_M_C
1st November 2006, 09:44
The script used for processing is at my plugins page. Since I used for preprocessing my other plugins, I thought it will be best to direct to my plugins page.



I am not sure which part is to be explained more. You may kindly visit my plugins page and see the watershed, SegmentedAmp and Retouch plugins for a more detailed explanation. However simply watershed assumes the image values as elevations and based on certain criterion draws watershed lines (just as a civil engineer does on land) and numbers individual basins. Retouch and SegmentedAmp are built over this segmentation, to alter the image values.
Watershed in more detail is availble through Google search.


Thx, i think i get the general idea now. I'll look into the plugins for more info too :)

foxyshadis
1st November 2006, 10:06
A couple minor bugs in SegmentedAmp:
The docs seem slightly out of date. useclip is default true, not false, and connect4 is now c4. Also, uv=false doesn't actually disable chroma processing.

Neat effect though. Occasionally corrupts avisynth's memory (goofy errors like can't locate decompressor, entirely black screen, that sort of thing), but not very reproducable and hasn't crashed yet.

vcmohan
3rd November 2006, 03:10
A couple minor bugs in SegmentedAmp:
The docs seem slightly out of date. useclip is default true, not false, and connect4 is now c4. Also, uv=false doesn't actually disable chroma processing.
Thanks for pointing out. I have corrected the mistakes. It should work correctly now.

Neat effect though. Occasionally corrupts avisynth's memory (goofy errors like can't locate decompressor, entirely black screen, that sort of thing), but not very reproducable and hasn't crashed yet.
I did not get any such message or error so far in my testing. Will continue to go thru my code to see if theres a bug.

foxyshadis
4th March 2007, 14:07
In testing lots of filters for this one extremely difficult image (a print scan with a great deal of halftoning patterns), SegmentedAmp performed the best by far in concert with some other filters. The memory allocation pattern won't work for this sort of image, but I can work around that no prob with a quick change. (Probably wasn't expecting many 4000x2000 frames...)

But the problem I'm running into is that it doesn't do any smoothing at all on the segment lines. Removegrain is a great help, but it still comes out looking like cracking paint on canvas. Here's a progression to show how it goes, with the effect exaggerated with levels:
http://foxyshadis.slightlydark.com/random/touhou_set.jpg
Otherwise, it's the only thing that can take care of screening without objectionable artifacts. (Although AdaptiveMedian made some pretty neat-o brush-stroke artifacts.)

If I have to I'll just mod the filter to output a mask of the segment divisions, but since you're the master, I figure you'd know of a better way.

If it matters, the exact use is:

clip2=removegrain(17).removegrain(17).mipsmooth(preset="AnimeLQ",temporal=255,temporal_chroma=255,spatial = 255).fft3dfilter(bt=1,sigma=10,sigma2=10,sigma3=10,sigma4=5,plane=4)
SegmentedAmp(sclip=clip2,useclip=true,c4=false)
clip2=removegrain(17).removegrain(17).mipsmooth(preset="AnimeLQ",temporal=255,temporal_chroma=255,spatial = 255).fft3dfilter(bt=1,sigma=10,sigma2=10,sigma3=10,sigma4=5,plane=4)
SegmentedAmp(sclip=clip2,useclip=true,c4=false)

vcmohan
5th March 2007, 03:18
Just plain watershed filter outputs basins or basin boundaries or both. May be you may be able to get a mask from it. Using a blurred image for input to watershed will reduce number of segments. The sharpen parameter is to treat the segment boundary lines. Try using different values.

vcmohan
7th October 2015, 13:18
SegmentedAmp is now available for avisynth+ also