daily pastebin goal
83%
SHARE
TWEET

Untitled

a guest Dec 10th, 2018 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.awt.Color;
  2.  
  3. /**
  4.  * Ujian Akhir Semester
  5.  * Kelas PBO B
  6.  * @author Hendra Ramadani (05111740000055)
  7.  * 10 December 2018
  8.  */
  9. public class ThresholdFilter extends Filter
  10. {
  11.     /**
  12.      * Constructor for objects of class ThresholdFilter.
  13.      * @param name The name of the filter.
  14.      */
  15.     public ThresholdFilter(String name)
  16.     {
  17.         super(name);
  18.     }
  19.  
  20.     /**
  21.      * Apply this filter to an image.
  22.      *
  23.      * @param  image  The image to be changed by this filter.
  24.      */
  25.     public void apply(OFImage image)
  26.     {
  27.         int height = image.getHeight();
  28.         int width = image.getWidth();
  29.         for(int y = 0; y < height; y++) {
  30.             for(int x = 0; x < width; x++) {
  31.                 Color pixel = image.getPixel(x, y);
  32.                 int brightness = (pixel.getRed() + pixel.getBlue() + pixel.getGreen()) / 3;
  33.                 if(brightness <= 85) {
  34.                     image.setPixel(x, y, Color.BLACK);
  35.                 }
  36.                 else if(brightness <= 170) {
  37.                     image.setPixel(x, y, Color.GRAY);
  38.                 }
  39.                 else {
  40.                     image.setPixel(x, y, Color.WHITE);
  41.                 }
  42.             }
  43.         }
  44.     }
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top