Image processing Formulas

Hi so I'm in trouble a bit. I've been following this tutorials: and I'm getting a bit of trouble to understand how to transform a formula in processing code. Looking the code from the tutorial I only see short cut codes to make a exact image processing but I can't see the actual formula like in C/C++ ..etc cos, sqrt..etc I got few complex formulas and I can't understand how to use them to process my image, any help with that?

I know many of you will ask me "give us your formula" but until giving the formula can you explain me how I could use one here, give me an example of a simple formula so I could understand.

Thanks, D.60


  • There are different ways you can transform images, the tutorial covers one way which is simple pixel level transformation. A pixel is a 32bit (ARGB) value comprising of four 8bit channels:
    0-7 blue channel
    8-15 green channel
    16-23 red channel
    24-31 alpha (transparency) channel

    Pixel manipulation generally involves bit-manipulation and you wouldn't see a cos or sqrt anywhere.

    So I think you should explain the type of image transformation you want to achieve.

  • Have you seen the image processing with formulas like getpixel / putpixel and operating the same formula for each pixel?

  • I think it still would not hurt to show your formula, the best way to deal with this depends on what exactly you want to do. It's hard to help someone, when you don't know his problem/goal/code. ( And one gets the impression, that it's your homework to write a basic example of pixel-manipulation... )

    Anyways, here is very simple example:

    PImage img;
    void setup() {
      size(400, 400);
      img = loadImage("moonwalk.jpg");
      image(img, 0, 0);
    void draw() {
    void mouseClicked() {
      for (int i= 0; i< img.pixels.length; i++) {
        img.pixels[i] = 0xffffffff - img.pixels[i];
      image(img, 0, 0);
  • My problem/goal is to program/make a code that will process images (pixels) and I need to apply a formula to the image(each pixel) and get a output/2nd image result. For example Gaussian filter, edge detection and other. To be totally honest It's a homework for me and I suck at image processing, the task is to get a formula and apply that formula to each pixel of the inserted image and get a output result a 2nd image.

    I wanted to try it with other programming codes like C# but I thought processing has already examples ..etc Would be more easy to make but the problem is I don't know how to insert that formula.

    I would accept any help.

    Thanks. D.60

  • The difficult part with such problems is that you can't just take a pixel, apply a formula and store the result as a pixel in another image. You need to take into account the pixels surrounding the pixel you're currently processing!

  • Ok, (I've seen the video) so how exactly I apply the formula on a 3x3, 4x4, 5x5..etc ?

  • This might be a good example to start with:

  • Do you understand how you apply a 3x3 kernel?

    In the video, the guy demonstrates how to apply two different 3x3 kernels: an average kernel (all positions have a value of 1) and an Gaussian kernel. Can you start with a 3x3 average kernel? Can you extend it to 5x5? An arbitrary number? Can you change it to the small Gaussian kernel the guy uses in the video? Can you find a formula to calculate the Gaussian kernel for an arbitrary size?

  • edited October 2015

    I found this video: It's almost the same the video you send me and example of formulas that I have to use at 01:15 F(u,v)= 1/N (the big Greek"Sigma" letter)..etc as I understand getting a 3x3 matrix and calculating with the formula each pixel and apply it/generate a new image with the applied formula.

    The point is that I don't know how to do that in code. I found a example of c# code:

    public  static bool ConvertToGrey (Bitmap b)
      for (int i=0; i<b.Width; i++)
        for(int j=0; j<bHeight; j++)
          color c1 = b.GetPixel(i, j);
          int r1 = c1.R;
          int g1 = c1.G;
          int b1 = c1.B;
          int grey =(byte).(.299 * r1 + .587 * g1 + .114 * b1);
          r1 = grey;
          g1 = grey;
          b1 = grey;
          b.SetPixel(i, j, )
      return true;
  • I have to do : 1. Hartley transform 2. Edge gradient detection 3. Power law point transformation 4. Homomorphic filtering

    I hope someone can help me at least with the 3x3 formula, get/put pixel or how ever it's called :D

    I'm eyes and ears to learn but when teacher tell you to do something and they don't give a dam information about how to do it, it piss me off and after that they say " don't copy from the internet" or "you copy/pasted from the internet" How to learn something when teachers don't teach anything :D Teachers Logic 101

    I will apreciate any kind of help, I will read anything you give me just help me, someone :D I'm desperate.

    Thanks, D.60

  • that's not complete, line 15 is missing an argument, or 3

    that's also only working on a single pixel, not a matrix.

    there are convolution examples here:

    search for Level II: Pixel Group Processing

  • Is there any other language that someone could know that I could use and apply my formula inside the code? Because processing looks kinda messy, It's nice but transforming the formula into a type of code it's hard, it's better when there is math lib's and you just apply the math words and write directly down the formula.

  • I'm eyes and ears to learn but when teacher tell you to do something and they don't give a dam information about how to do it, it piss me off and after that they say " don't copy from the internet" or "you copy/pasted from the internet" How to learn something when teachers don't teach anything Teachers Logic 101

    I agree partially, but a good programmer should be able to figure out things himself. It's a crucial skill and sadly the only way to develop is to be told to do something but not be told how... I agree it's super annoying but something that's unavoidable. Also if you're stuck on a problem like this for a while, and you find a solution, you'll likely remember it better.

    A good place to look for a solution is the reference.

  • I agree with you too, that a person learn better on his own instead of someone teaching him but what's the point of going College/University if you can learn on your own. About the coding/programming how you gonna learn good skills and tricks if teacher/professor don't teach you anything and only gives you problems without examples.

    Ok about pixels but what about formulas?

  • we've been over that a 1000 times in your other thread.

    you still have difficulties to grasp what an algorithm does....

    an algorithm is essentially a formula formulated as a task list for the computer.

  • why did you start a new thread?

  • other thread? When was that?

  • @Chrisir well spotted I have closed the previous discussion. It is full of useful information but this appears to be the same question asked 2 months on.

  • edited October 2015

    @benja provided an example

    This might be a good example to start with:

    It shows quite clearly how to apply a convolution matrix. I don't know where you got your 'formulas' from (maybe wikipedia?) but perhaps you should be looking for the convolution matrix values for the transformation you seek then plug them into the example.

    but what's the point of going College/University if you can learn on your own.

    The point of education is to structure the students learning, expose them to new ideas and help make them become independent learners.

    'How to teach something that the students can learn and build on' :D Teachers Conundrum 101

  • Yea about the last post I totally forgot about it I apologise. About taking a line of what I said it makes way different meaning instead of what I said. I know thats exactly what University do but sometimes when profesors don't teach how to do some tasks and giving you problems you start searching help from internet, Posting a thread about something doesn't mean you understand everything someone needs to explain you and answer your questions to unlock that doors in your brain and fully understand.

    I'm totally sorry If I'm annoying but I don't understand because of lack of information and that's make people sometimes angry and confused.

    So let's get back to business:

    I wrote that convolution post and I understand that processing a img in that way you make a matrix (3x3 or more) to process the image and calculate the middle and around pixels in that way your 2nd image will be generated.

    For example I have "Hartley Transform" the formula is not for wikipedia teacher gave us that formula and we need to insert that formula inside the code

    It's like F(u,v) = 1/N N-1 Sigma j=0 N-1 Sigma k=0 F(j,k) cas { 2π/N (uj=vk) } that kind of formula.

    To be honest is my 1st time in image processing and I do my best to understand what's going on. ps(It's not my 1st time programming ofc not in processing)

  • if you had really followed your last thread, you would be used to image processing by now....

    to post a formula like you did you need to format it as code I guess, because otherwise the * get lost... so go back, edit your post and format the formula as code....

    greek sigma means sum of....

    cas.... do you mean cos....?

    what do the other variables stand for?

  • Cas(t) = cos(t) + sin(t), see this Wikipedia article:

  • So basically I need Hartley transform and process a image :) Some people told me that it's easier to work with formulas and image processing in C or C#

Sign In or Register to comment.