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 7808529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:09:43+00:00 2026-06-02T03:09:43+00:00

I am trying to calculate the standard deviation for an image in java. I

  • 0

I am trying to calculate the standard deviation for an image in java. I am using rast.Sample to get each grey level and then I am taking it away from the mean and squaring it.

My code is:

public int standardDeviation(BufferedImage source)
    {
    int width = source.getWidth();
    int height = source.getHeight();
    int totalPixels = width * height;
    int temp = 0;
    int VarianceSum = 0;
    double SumSquared = 0;
    int mean = mean(source);
    double variance = 0;
    int StandardDeviation = 0;
    Raster rast = source.getRaster();

    //Loop through rast getting each grey level.
    for(int i =0; i<width; i++)
        {
            for(int j=0; j<width; j++)
            {
                temp = rast.getSample(i,j,0);
                VarianceSum += (temp - mean);
                SumSquared = Math.pow(VarianceSum,2);
            }
        }

    variance = SumSquared/totalPixels;


    System.out.println(temp);
    System.out.println(VarianceSum);
    //System.out.println(SumSquared);
    System.out.println(totalPixels);



    return StandardDeviation;

    }

I am doing something silly! Please help

  • 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-06-02T03:09:44+00:00Added an answer on June 2, 2026 at 3:09 am

    You iterate over the width two times. Will crash if width != height. Also see my comment

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

Sidebar

Related Questions

am trying to calculate mean and variance using 3X3 window over image(hXw) in opencv...here
I am trying to calculate a determinant using the boost c++ libraries. I found
I'm trying to calculate the sunset / rise times using python based on the
I need to calculate the mean, standard deviation, and other values for a number
I'm trying to calculate the (cross?) correlation between a template image (an image which
I am trying to manually calculate the standard error of the constant in an
Recently I was trying to determine the time needed to calculate a waveform using
I'm trying to calculate whether the results i get from the database are made
I'm tring to calculate the standard deviation of a vector of doubles (called A).
I'm trying to calculate correlations in Perl. I found out how to calculate correlations

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.