Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7443389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:19:22+00:00 2026-05-29T11:19:22+00:00

My assignment is to write a monochrome (black and white) fog filter to change

  • 0

My assignment is to write a monochrome (black and white) fog filter to change an image so it looks like it was taken on a foggy day. To do this, change every value in the image to the average of the value itself, the values next to it (4 or all 8) and a random value from 0 to 255 ((short)(Math.random() * 256) will get you the random number). My teacher doesn’t respond on weekends for help.

So here’s where I’m at:
I’ve improved my code because it makes the image black and white. But I thought that it would standout more then black and white. I just want to make sure that I am atleast doing what the assignment asked.

The teacher has designed a few of his own classes for this assignment and an Interface

ImageProvider class that provides the image (a .jpg picture)
java.lang.Object
extended byjava.awt.Component
extended byimagelab.ImgProvider

All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

ImageLab class
java.lang.Object
extended byimagelab.ImageLab

ImageLab is a platform for image filter development. ImageLab begins by building a menu of all available filters (those .class files that implement the ImageFilter interface @see ImageFilter).

Interface ImageFilter

public interface ImageFilter

The ImageFilter interface is implemented by the respective image filters.

Implementation Detail The format of the program
When writing a filter you should indicate that the filter is a member of the filter package by placing the line:
package filters; at the top of the .java file.

So your filter can find the ImageFilter interface, you should put the line:
import imagelab.*; as the second line in the file.

To compile your filter (assume its called MyFilter.java), go to the parent directory (the directory that has imagelab and filters as subdirectories) and type:
javac filters/MyFilter.java

To run imageLab, you should be in the same directory and type:
java imagelab.ImageLab

package filters;
import imagelab.*;

public class Monochrome implements ImageFilter {

    ImgProvider filteredImage;

public void filter (ImgProvider ip) {

    short[][] mono = ip.getBWImage();//Convert the picture to B&W

    short[][] mono2 = new short[mono.length][mono[0].length];

    /**Go through both arrays and change every value in the image to the average of the value itself, the values next to it (4 or all 8) and a random value from 0 to 255
    */
    for (int r = 1; r<mono.length-1; r++) {
        for (int c = 1; c < mono[0].length-1; c++) { 
            int val = mono[r][c];
            val += ((short)Math.random()*256); //random number
            val += mono[r-1][c];
            val += mono[r+1][c]; 
            val += mono[r][c-1];
            val += mono[r][c+1];
            val /= 5;
            val = (val < 0) ? -val : val;
            if (val > 255) val = 255;
            mono2[r][c] = (short)((val < 0) ? -val : val);      
        }//for c
    }//for r;

    filteredImage = new ImgProvider(); //create the new .jpg image 
    filteredImage.setBWImage(mono2); //set it to B&W using the monochrome settings
    filteredImage.showPix("Monochrome of original image"); //label the image
}//filter

public ImgProvider getImgProvider() {
    return filteredImage;
}//getImgProvider

public String getMenuLabel() {
    return "Monochrome";
} //getMenuLabel

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:19:23+00:00Added an answer on May 29, 2026 at 11:19 am

    You state you need to "change every value in the image to the average of the value itself, the values next to it (4 or all 8) and a random value from 0 to 255"

    You’re currently not doing anything like that; you’re assigning a randomly chosen location to your current location as you go through the arrays.

    Your 2 loops to go through the entire 2D array are fine, but you need to get the values of those surrounding the one you’re currently at.

    Example: If you’re at mono[0][0] then you need to get mono[0][1],mono[1][0], and mono[1][1]. Add those together along with your current location’s value and the random number then divide by 5 to get the average.

    You’ll note I picked a corner for the example. Depending on where you are in the 2D array you could have 3 (you’re in a corner), 5 (you’re on the border but not in a corner) , or 8 (you’re in the interior) surrounding values; I don’t know where 4 came from in your description.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can you write something like this in C with multiple assignment operations? int a
This is my assignment: Write a program where the user enters a string, and
This is the assignment: Write a method that sorts the elements of a matrix
my assignment question is like that Write a program which prints the letters in
I have this assignment to read, write, enable cookies so that the username will
I have two questions about this homework assignment: Write an assembly language program in
Here is my code for this simple assignment: Write the code that will read
Assignment: Write a C++ program to read the menu information from menu.txt. First letter
I have the following assignment: Write a complete 8086 program to perform the calculator
My kiddo had a homework assignment to write Blackjack in Java. I helped him

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.