Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

compute mean and standard deviation of RGB color

Posted on 1998-04-15
4
Medium Priority
?
351 Views
Last Modified: 2008-03-17
Hello..., I really need your help..URGENT..and please reply as soon as
possible. I was given a few sample of images in BMP format (device-
independent-bitmap(DIB). Can you give me a few sample of the source code
on how to compute the mean and the standard deviation on the RGB color
for each sample to take the average color to get the standard color of the
image( for example I took 10 sample of images of pepper berries). Thanx.
0
Comment
Question by:juexxs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 11

Expert Comment

by:alexo
ID: 1184303
Sounds like homework...
0
 
LVL 22

Expert Comment

by:nietod
ID: 1184304
I'm not sure.  That sounds too weird to be even homework.  

There is a lot involved in this process.  Can you tell us what you problem areas are?  also if it is homework, we will still be happy to HELP you, but we won't do it for you.  For (100 points on a question of this size, no one is likely to do it for you in any case).
0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 120 total points
ID: 1184305
Should be fairly simple..

Load the bitmap file into a HBITMAP object in memory

Once you have the bitmap object, associate a device context with it (CreateCompatibleDC and select the bitmap into it).

You can get the RGB (COLORREF) data at any pixel with GetPixel()

Write nexted for loops that go through the entire bitmap and accumulate and count the rgb components of each pixel.  Then do the statistics

An alternative is to use some of the OpenGL code which reads in bitmap files and stores them in an array of RGB values.  Then you can just do some array arithmetic

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1184306
Here is some code using OpenGL functions to read in the bitmap from a file and compute the average colour

#include <glu.h>
#include <GLAUX.H>

COLORREF AverageColor (LPCTSTR filename) {
  AUX_RGBImageRec *pImage;

  glPixelStorei(GL_PACK_ALIGNMENT, 1);
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

  pImage = ::auxDIBImageLoad(filename);

  int sum[3] = {0,0,0};
  int ave[3];

  int n = pImage->sizeX*pImage->sizeY;
  for (int i = 0; i < n*3; i+=3) {
    sum[0] += pImage->data[i+0];
    sum[1] += pImage->data[i+1];
    sum[2] += pImage->data[i+2];
  }
  ave[0] = unsigned char (sum[0]/n);
  ave[1] = unsigned char (sum[1]/n);
  ave[2] = unsigned char (sum[2]/n);

  return RGB(ave[0],ave[1],ave[2]);
}

You can expand this to do std dev etc.

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question