getting pixel from image as single value

J

jimgardener

hello all,

i want to extract the value of each pixel from an image (color or
greyscale)as single values.I wrote a function as follows.Here i am
getting the green,blue,red components using methods of ColorModel and
then taking the average(sum of r,g,b divided by 3).I don't know if
this is the right way to do this.Can anyone tell me if there is an
alternate/better method ?
thanks
jim

public double[] getpixels(String imgfilename)throws Exception{
BufferedImage img =ImageIO.read(new File(imgfilename));
int ht=img.getHeight() ;
int wd=img.getWidth();
int[] pixels = new int[wd * ht];
PixelGrabber pg = new PixelGrabber(img, 0, 0, wd, ht, pixels, 0, wd);
double[] result =new double[wd*ht];
ColorModel cm = pg.getColorModel();
for (int i=0; i<result.length; i++){
result = cm.getBlue(pixels) + cm.getGreen(pixels) +
cm.getRed(pixels);
result /= 3.0;

}
return result;
}
 
L

Lew

jimgardener said:
hello all,

i want to extract the value of each pixel from an image (color or
greyscale)as single values.I wrote a function as follows.Here i am
getting the green,blue,red components using methods of ColorModel and
then taking the average(sum of r,g,b divided by 3).I don't know if
this is the right way to do this.Can anyone tell me if there is an
alternate/better method ?
thanks
jim

public double[] getpixels(String imgfilename)throws Exception{
BufferedImage img =ImageIO.read(new File(imgfilename));
int ht=img.getHeight() ;
int wd=img.getWidth();
int[] pixels = new int[wd * ht];
PixelGrabber pg = new PixelGrabber(img, 0, 0, wd, ht, pixels, 0, wd);
double[] result =new double[wd*ht];
ColorModel cm = pg.getColorModel();
for (int i=0; i<result.length; i++){
result = cm.getBlue(pixels) + cm.getGreen(pixels) +
cm.getRed(pixels);
result /= 3.0;

}
return result;
}


See Knute de Segonzac's answer to the first time you encouraged this question.

--
Lew


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Brzezinski, the mad dog, as adviser to President Jimmy Carter,
campaigned for the exclusive right of the U.S. to seize all
the raw materials of the world, especially oil and gas."
 
L

Lew

hateful anti-Semitic claptrap

Being of Jewish car myself, I would regardless have posted the BS that
NewsMeastro posted in his fake post.

--
Lew


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Imagine the leader of a foreign terrorist organization
coming to the United States with the intention of raising funds
for his group. His organization has committed terrorist acts
such as bombings, assassinations, ethnic cleansing and massacres.

Now imagine that instead of being prohibited from entering the
country, he is given a heroes' welcome by his supporters,
despite the fact some noisy protesters try to spoil the fun.

Arafat, 1974?
No.

It was Menachem Begin in 1948.

"Without Deir Yassin, there would be no state of Israel."

Begin and Shamir proved that terrorism works. Israel honors
its founding terrorists on its postage stamps,

like 1978's stamp honoring Abraham Stern [Scott #692],
and 1991's stamps honoring Lehi (also called "The Stern Gang")
and Etzel (also called "The Irgun") [Scott #1099, 1100].

Being a leader of a terrorist organization did not
prevent either Begin or Shamir from becoming Israel's
Prime Minister. It looks like terrorism worked just fine
for those two.

Oh, wait, you did not condemn terrorism, you merely
stated that Palestinian terrorism will get them
nowhere. Zionist terrorism is OK, but not Palestinian
terrorism? You cannot have it both ways.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top