Problems with an exercise (FalseColor)

edited June 2016 in Questions about Code

Hi, I'm an italian student! I'm working on a program but I can't create the entire correct code. Can I write the exercise text and ask for help?

Tagged:

Answers

  • Yes

    Best post your code, what you tried and where you are stuck

  • edited June 2016

    This is the exercise text:

    Purpose of the exercise is to show how you can produce a color image from a picture in black and white. To accomplish this you must perform the following steps, in the following order:

    1. Write the function (ReadImage) that reads an image by offering the user the window for selecting the file that contains it, and the charge in a PImage object. The function has no arguments and returns the result Pimage object.

    2. Define the FalseColor function that transforms an input pixel color in a false color. The function first converts the color to a gray level calculated as the average color: gl = (red + green + blue) / 3 Subsequently, the function converts the gray false color (or pseudocolor) this way: if gl is less than or equal to 80, then the colorFC color components [r g b] equal to [0 0 c] where c = gl * 255/80 if gl is between 80 and 160 the components are [0 255 c] where c = (gl-80) * 255/80 Finally, if gl is between 160 and 255 components are [255 c 255] where c = (gl- 160) * 255/95

    3. Define the function Transform (imageOR, x, y, truck width, height). The Transform function takes as arguments an image (imageOR) and the coordinates of a rectangular region of which x and y are the coordinates of the upper left corner and the width and height are the dimensions. The function must be transformed into false color only pixels included in the specified rectangular region. To do so you must use the FalseColor function.

    4. Define a script that loads an image chosen by the user using the ReadImage function and display it. The user can define a rectangular area by dragging the mouse (after doing a click with the mouse button on left move the mouse while holding the button). That region of the script applies the transformation in false color.

    I tried and make just this for now

    PImage imageOR;
    color colorFC;
    
    
    void setup() {
     String ReadImage = selectInput ("Load an image");
     imageOR = loadImage (ReadImage);
     size (imageOR.width, imageOR.height);
     image(imageOR, 0, 0);
    }
    
    
    void FalseColor() {
      loadPixels();
      for (int numPixel=0; numPixel<(imageOR.width*imageOR.height); numPixel=numPixel++) {
        color gl = color ((red(imageOR.pixels[numPixel])+green(imageOR.pixels[numPixel])+blue(imageOR.pixels[numPixel]))/3);
        color coloreFC = color (0, 0, 0);
    
        if( gl <= 80 ) {
          color c = gl*(255/80);
          colorFC = color (0, 0, c);
          pixels[numPixel] = coloreFC;
        } else if( gl < 160 || gl > 80) {
          color c = (gl-80)*(255/80);
          colorFC = color (c, 0, 255);
          pixels[numPixel] = coloreFC;
        } else if( gl < 255 || gl > 160) {
          color c = (gl-160)*(255/95);
          colorFC = color (255, c, 255);
          pixels[numPixel] = coloreFC;
        }
        updatePixels();
      }
    }
    

    It's really incomplete and there's something wrong.

    Please help me, thanks!

Sign In or Register to comment.