Take the 2-minute tour ×
Graphic Design Stack Exchange is a question and answer site for Graphic Design professionals, students, and enthusiasts. It's 100% free, no registration required.

In Gimp, how can I multiply the value of every pixel in a grayscale image by a constant value? For example, multiply each pixel by 2.

share|improve this question
add comment

3 Answers 3

Pixel math is tricky (and a little slow) in Gimp, either using a script (i.e. invoking for each pixel gimp-drawable-set-pixel with Script-Fu or Python-Fu ) or using plug-ins like MathMap.

Note that multiplying by a constant could increase the value of the pixels over the maximum range for the image, and after the operation you can have some saturated areas. I don't know if the current version of Gimp has already a built-in support for working with 16-bit (or more) grayscale images and I suggest you to perform pixel multiplications with ImageJ which, despite the poor user interface, is very fast and useful for this kind of operations, and can manage values up to 32-bit grayscale images.

Gimp is a great image manipulation program, but in this case I think that ImageJ could be a more proper tool.

share|improve this answer
add comment

Another way to think of this problem, instead of saying that you are multiplying each pixel value by 2, is to say that your are taking pixels in the range of (0,127) and are stretching them to fill the whole range (0,255).

When you look at it that way, it is very easily done in the "Levels" tool.

Set the input levels "white point" to 127, and leave the output levels "white point" as 255, and everything will be scaled up.

Image of GIMP Levels dialog with settings as described in text

For other multiplication factors, you just have to do a quick calculation to figure out what input value should equal 255 output.

If you wanted to divide the pixel values for some reason, you would leave the input white point as 255 and reduce the maximum output level.

share|improve this answer
add comment

I thought of an additional way to do it:

Select the layer you want to multiply, then go to Filters -> Generic -> Convolution Matrix.

In the window that pops up, leave all the cells at zero except for the center cell which you should set to the value you wish to multiply by. It should look like this:

Convolution Matrix window

share|improve this answer
    
It should do the trick (until your start values are less than 128 or if your Gimp version is able to manage grayscale images deeper than 8 bits). If this way solves your problem, you can mark your own solution as a correct answer. –  Paolo Gibellini Dec 4 '13 at 9:03
    
So you're saying the pixel values must be less than 128 or else they will be saturated after multiplying by 2, right? –  Garrett Dec 4 '13 at 20:18
    
Exactly, until you use a 8-bit grayscale image. Future versions of Gimp should be able to manage deeper depth. –  Paolo Gibellini Dec 5 '13 at 10:00
    
Cool, thanks! By the way, I think you mean "assuming" instead of "until". –  Garrett Dec 5 '13 at 20:28
    
My English needs some improvement... ;-) –  Paolo Gibellini Dec 6 '13 at 17:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.