GIMP Chat
http://gimpchat.com/

Multi Threshold G'MIC plugin AKA "Pre Obama Posterize" Script.
http://gimpchat.com/viewtopic.php?f=9&t=14453
Page 1 of 2

Author:  trandoductin [ Wed Aug 24, 2016 12:18 pm ]
Post subject:  Multi Threshold G'MIC plugin AKA "Pre Obama Posterize" Script.

This is a G'MIC plugin script.
In Linux, look for a file called .gmic in your $HOME/ folder
On Windows, it's a filed called user.gmic in your %APPDATA%/ (on mine it's C:\Users\Tin Tran\AppData\Roaming\user.gmic
If it's not there create it.
If it's there paste this code in there at the appropriate place, i hope you're able to tell where the appropriate place is (I am guessing just end of file) I don't know because I previously don't have that file.
#@gmic
#@gimp <b>.{development filters}</b>

#@gimp Multi Thresholds : multi_threshold, multi_threshold
#@gimp : Threshold_1 = int(50,1,256)
#@gimp : Threshold_2 = int(100,1,256)
#@gimp : Threshold_3 = int(150,1,256)
#@gimp : Threshold_4 = int(200,1,256)
multi_threshold :
   --luminance[0] -threshold[-1] 1  -normalize[-1] 0,255 -to_colormode[-1] 4
   --luminance[0] -threshold[-1] $1 -normalize[-1] 0,255 -to_colormode[-1] 4
   --blend[-1,-2] difference -replace_color[-1] 0,0,255,255,255,255,9,0,1,255
   
   --luminance[0] -threshold[-1] {$1} -normalize[-1] 0,255 -to_colormode[-1] 4
   --luminance[0] -threshold[-1] {$2} -normalize[-1] 0,255 -to_colormode[-1] 4
   --blend[-1,-2] difference -replace_color[-1] 0,0,255,255,255,255,175,42,27,255
   
   --luminance[0] -threshold[-1] {$2} -normalize[-1] 0,255 -to_colormode[-1] 4
   --luminance[0] -threshold[-1] {$3} -normalize[-1] 0,255 -to_colormode[-1] 4
   --blend[-1,-2] difference -replace_color[-1] 0,0,255,255,255,255,101,101,101,255
   
   --luminance[0] -threshold[-1] {$3} -normalize[-1] 0,255 -to_colormode[-1] 4
   --luminance[0] -threshold[-1] {$4} -normalize[-1] 0,255 -to_colormode[-1] 4
   --blend[-1,-2] difference -replace_color[-1] 0,0,255,255,255,255,174,165,131,255
   
   --luminance[0] -threshold[-1] {$4} -normalize[-1] 0,255 -to_colormode[-1] 4
   --luminance[0] -threshold[-1] 256 -normalize[-1] 0,255 -to_colormode[-1] 4
   --blend[-1,-2] difference -replace_color[-1] 0,0,255,255,255,255,247,228,160,255
   
   -remove[-2,-3,-5,-6,-8,-9,-11,-12,-14,-15]
   
   --blend[-1,-2,-3,-4,-5] add
   
   -remove[-2,-3,-4,-5,-6]
   
   -move[-1] 0
   
   -remove[1]
   
#@gimp _

Alternately if you do not yet have the .gmic file or user.gmic file already just use this file.
Attachment:
user.gmic.zip [479 Bytes]
Downloaded 230 times


And then you'll have an available filter in G'MIC that looks like this.
Image
You can control these 4 thresholds on the fly and preview the result (a little slow but i am just happy it works).
Then after applying, you can run the Obama Posterize scheme script
And the result will reflect the manual multi thresholds that you used.

As an example here this result i have it reflects the thresholds that I used above.
Image

Warning: Threshold1 < Threshold2 < Threshold3 < Threshold4. Thresholds must be incrementally different. If a lower numbered threshold is higher than a higher numbered threshold, it'll poop out and give white areas. You've been warned. :hehe

Author:  garagecoder [ Wed Aug 24, 2016 1:05 pm ]
Post subject:  Re: Multi Threshold G'MIC plugin AKA "Pre Obama Posterize" Script.

G'MIC part is working fine, pretty sure it took a lot longer for me to get something useful out of G'MIC. Nicely done :yup

Author:  trandoductin [ Wed Aug 24, 2016 1:15 pm ]
Post subject:  Re: Multi Threshold G'MIC plugin AKA "Pre Obama Posterize" Script.

heheeh I don't think it's possible to take longer. I already milked all the hours out of the day hunting around for what i needed.
my goal was to make it work no matter how slow. :hehe

Author:  mackenzieh [ Wed Aug 24, 2016 5:33 pm ]
Post subject:  Re: Multi Threshold G'MIC plugin AKA "Pre Obama Posterize" Script.

This seems like a nice filter, but the folder doesn't come up for me in C:/Users/Mackenzie.

It only comes up in the search but the folder itself isn't visible. I have windows 7 64Bit

Author:  trandoductin [ Wed Aug 24, 2016 6:20 pm ]
Post subject:  Re: Multi Threshold G'MIC plugin AKA "Pre Obama Posterize" Script.

The AppData folder is defaulted as hidden folder.
Trying clicking on View when you're viewing your user's folder, and then tick the Hidden Items or something similar and it'll appear.
Image

Author:  mackenzieh [ Wed Aug 24, 2016 7:00 pm ]
Post subject:  Re: Multi Threshold G'MIC plugin AKA "Pre Obama Posterize" Script.

trandoductin wrote:
The AppData folder is defaulted as hidden folder.
Trying clicking on View when you're viewing your user's folder, and then tick the Hidden Items or something similar and it'll appear.
[ Image ]


I don't see anything like what your image showed. However, when I click properties, I see this:

Image

Author:  trandoductin [ Wed Aug 24, 2016 7:13 pm ]
Post subject:  Re: Multi Threshold G'MIC plugin AKA "Pre Obama Posterize" Script.

mackenzieh wrote:
trandoductin wrote:
The AppData folder is defaulted as hidden folder.
Trying clicking on View when you're viewing your user's folder, and then tick the Hidden Items or something similar and it'll appear.
[ Image ]


I don't see anything like what your image showed.

https://www.google.ca/search?q=how+to+show+hidden+files+on+windows+7&ie=utf-8&oe=utf-8&gws_rd=cr&ei=ETi-V8v9GoLhjAPcy4aoCA

Author:  mackenzieh [ Wed Aug 24, 2016 7:22 pm ]
Post subject:  Re: Multi Threshold G'MIC plugin AKA "Pre Obama Posterize" Script.

trandoductin wrote:
mackenzieh wrote:
trandoductin wrote:
The AppData folder is defaulted as hidden folder.
Trying clicking on View when you're viewing your user's folder, and then tick the Hidden Items or something similar and it'll appear.
[ Image ]


I don't see anything like what your image showed.

https://www.google.ca/search?q=how+to+show+hidden+files+on+windows+7&ie=utf-8&oe=utf-8&gws_rd=cr&ei=ETi-V8v9GoLhjAPcy4aoCA


I edited my previous post.

Author:  trandoductin [ Wed Aug 24, 2016 7:27 pm ]
Post subject:  Re: Multi Threshold G'MIC plugin AKA "Pre Obama Posterize" Script.

go to the link i posted it tells you how to do it on Windows 7 there are minor differences on different windows.

Author:  mackenzieh [ Wed Aug 24, 2016 7:37 pm ]
Post subject:  Re: Multi Threshold G'MIC plugin AKA "Pre Obama Posterize" Script.

trandoductin wrote:
go to the link i posted it tells you how to do it on Windows 7 there are minor differences on different windows.


I've changed my mind. I'll wait to see if the new version of GMIC gets this plugin installed.

Author:  trandoductin [ Wed Aug 24, 2016 8:41 pm ]
Post subject:  Re: Multi Threshold G'MIC plugin AKA "Pre Obama Posterize" Script.

i don't know what the process is for it to get into the next build.

Author:  mackenzieh [ Wed Aug 24, 2016 9:11 pm ]
Post subject:  Re: Multi Threshold G'MIC plugin AKA "Pre Obama Posterize" Script.

trandoductin wrote:
i don't know what the process is for it to get into the next build.


Me neither but I'm okay with waiting to see if it gets into the next build.

Author:  MareroQ [ Thu Aug 25, 2016 1:11 am ]
Post subject:  Re: Multi Threshold G'MIC plugin AKA "Pre Obama Posterize" Script.

It works great in Vista 32 Bit (for GIMP 2.8.18 i 2.9.5)
I changed a location in the menu GMIC.
Thanks Tin. :jumpclap

Attachments:
MultiThresholds.png
MultiThresholds.png [ 38.62 KiB | Viewed 1480 times ]

Author:  trandoductin [ Thu Aug 25, 2016 10:56 am ]
Post subject:  Re: Multi Threshold G'MIC plugin AKA "Pre Obama Posterize" Script.

MareroQ, do you know what the process is (in order to get it into the next G'Mic build)?

Author:  Rod [ Thu Aug 25, 2016 11:07 am ]
Post subject:  Re: Multi Threshold G'MIC plugin AKA "Pre Obama Posterize" Script.

Image

I just opened notepad ++ and created the file and saved as "user.gmic" in the roaming folder in windows 10. :bigthup
Thanks, this works nicely for preview before executing the script.

Image

Author:  trandoductin [ Thu Aug 25, 2016 11:12 am ]
Post subject:  Re: Multi Threshold G'MIC plugin AKA "Pre Obama Posterize" Script.

but it is still slow...at least i think so
for each threshold color i had to blend 2 layers using subtract mode so 10 layers + 5 result layers, then blend all 5 layers using addition at the end.
If i only knew what blending mode to use to get normal like what how Gimp treats layers I think it'd be much faster.

Author:  garagecoder [ Thu Aug 25, 2016 11:26 am ]
Post subject:  Re: Multi Threshold G'MIC plugin AKA "Pre Obama Posterize" Script.

Hopefully when David's back he will add a new gmic community file for you (so it appears on filter list after refresh).

Perhaps the blending mode you're after is "blend alpha" ?

I may have time at the weekend to look more closely and help speed things up...

Author:  trandoductin [ Thu Aug 25, 2016 1:01 pm ]
Post subject:  Re: Multi Threshold G'MIC plugin AKA "Pre Obama Posterize" Script.

I have looked that this page https://sourceforge.net/p/gmic/wiki/Blending%20modes/
And none of the modes does a normal gimp layer over top of layer result.

Correction: Alpha seems like what i want to do according to the above page...but when i try it it doesn't seem to want to work i keep getting a whole layer filled with one color.

Author:  garagecoder [ Thu Aug 25, 2016 2:13 pm ]
Post subject:  Re: Multi Threshold G'MIC plugin AKA "Pre Obama Posterize" Script.

OK I couldn't resist :oops:

Here's another way of doing it:

#@gimp Multi Thresholds : multi_threshold, multi_threshold
#@gimp : Threshold_1 = int(50,0,255)
#@gimp : Threshold_2 = int(100,0,255)
#@gimp : Threshold_3 = int(150,0,255)
#@gimp : Threshold_4 = int(200,0,255)
multi_threshold :
  -repeat $! -l[$>]
    -split_opacity --rgb2ycbcr[0] -channels. 0 -fc[0] 9,0,1
    --fc[0] 175,42,27 --ge[-2] $1 -j[0] [-2],0,0,0,0,1,[-1] -rm[-2,-1]
    --fc[0] 101,101,101 --ge[-2] $2 -j[0] [-2],0,0,0,0,1,[-1] -rm[-2,-1]
    --fc[0] 174,165,131 --ge[-2] $3 -j[0] [-2],0,0,0,0,1,[-1] -rm[-2,-1]
    --fc[0] 247,228,160 --ge[-2] $4 -j[0] [-2],0,0,0,0,1,[-1] -rm[-2,-1]
    -rm. -a c
  -endl -done


There are even shorter ways but then it becomes hard to read.

Some explanation:
--rgb2ycbr -channels. 0 = another way of getting luminance
--fc[0] r,g,b = take a copy of image [0] and fill with rgb color
--ge[-2] x = create a new image from luminance, any value greater than or equal to x will be 1
-j[0] [-2],0,0,0,0,1,[-1] = draw image [-2] onto image [0] using [-1] as a mask

Author:  trandoductin [ Thu Aug 25, 2016 2:18 pm ]
Post subject:  Re: Multi Threshold G'MIC plugin AKA "Pre Obama Posterize" Script.

I have no idea how you do it..but this version is awesome it doesn't bug out when threshold is out of whack either and seems
super fast.
Great...now how do we get this into the next build?

Page 1 of 2 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/