It is currently Mon Jul 22, 2024 12:27 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Implementing (1-image*2)^2
PostPosted: Tue Mar 11, 2014 1:03 am  (#1) 
Offline
New Member

Joined: Mar 10, 2014
Posts: 3
I have a gray-scale image in Gimp and I want to process it like this:
*multiply image by 2
*subtract 1
*square the image (i.e. image*image)

In short output = (1-image*2)^2

So if have the following input image:
Image
The expected result is:
Image

The math is dead simple and it works if I use math nodes in Blender,
so the problem is my G'MIC implementation:
#@gimp Simple eq: simple_eq, simple_eq
simple_eq :
-to_gray
-mul -2
-add 1
-sqr


I thought maybe the problem is G'MIC processing the image as 8bit integer
instead of float, but if I try to convert it with -int82float I get an error.

Someone knows how to implement this equation in G'MIC?
Maybe you have to use int82float but you can't because Gimp doesn't support float images?
Is there a workaround to get the same result?


Attachments:
test_gradient_result.png
test_gradient_result.png [ 685 Bytes | Viewed 1626 times ]
test_gradient.png
test_gradient.png [ 9.2 KiB | Viewed 1626 times ]
Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Implementing (1-image*2)^2
PostPosted: Tue Mar 11, 2014 1:26 am  (#2) 
Offline
GimpChat Member
User avatar

Joined: Jan 03, 2011
Posts: 1656
Even if G'MIC does all its computation using float values, it reads pixel values as they are stored in the image file, so for a .JPEG file, the pixel values will be probably in range [0-255]
(few JPEG files store data in 12bits integers, but it is rarely the case). GIMP also transfer image data to the G'MIC plug-in as 8bits integers.
Actually, you cannot assume that the values are normalized in [0-1], and you must explicitly divide the values by 255 and re-multiply them afterwards, in your processing code if you need too :

charblaze wrote:
G'MIC implementation:
#@gimp Simple eq: simple_eq, simple_eq
simple_eq :
-to_gray
-div 255
-mul -2
-add 1
-sqr
-mul 255



Note that you can also uses the '-fill' command, with a mathematical expression. It is probably a bit slower, but easier to read :

simple_eq :
  -to_gray -fill '255*(1-2*i/255)^2'


Top
 Post subject: Re: Implementing (1-image*2)^2
PostPosted: Tue Mar 11, 2014 7:37 am  (#3) 
Offline
New Member

Joined: Mar 10, 2014
Posts: 3
Thank you!

I thought G'MIC loaded and worked on images as floats, converting everything to 8bit when bringing back the results to Gimp.

I didn't know you can access the pixel value from a mathematical expression, nice tip.


Top
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Retexture an image with another image as "Image Pattern" Plug-in

4

No new posts Show image on web browser to fill 100% width AND image map

2

No new posts Attachment(s) image name

2

No new posts Attachment(s) Celebration image

19

No new posts Attachment(s) Image to bit map file

7



* Login  



Powered by phpBB3 © phpBB Group