Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > getting pixel from image as single value

Reply
Thread Tools

getting pixel from image as single value

 
 
jimgardener
Guest
Posts: n/a
 
      07-09-2008
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[i] = cm.getBlue(pixels[i]) + cm.getGreen(pixels[i]) +
cm.getRed(pixels[i]);
result[i] /= 3.0;

}
return result;
}



 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      07-09-2008
jimgardener wrote:
> 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[i] = cm.getBlue(pixels[i]) + cm.getGreen(pixels[i]) +
> cm.getRed(pixels[i]);
> result[i] /= 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."

 
Reply With Quote
 
 
 
 
conrad@lewscanon.com
Guest
Posts: n/a
 
      07-15-2008
On Jul 15, 5:39*am, the *fake* Lew <(E-Mail Removed)> wrote:
> hateful anti-Semitic claptrap


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

--
Lew
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      07-17-2008
On Jul 15, 5:39=A0am, the *fake* Lew <(E-Mail Removed)> wrote:
> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
getting pixel data from image as single value jimgardener Java 1 07-08-2008 08:52 PM
Fuji S3000 - 3.2 m/pixel or 6 m/pixel? Peter H Digital Photography 3 11-18-2003 11:17 PM
Re: Pixel size of individual Pixel Robert E. Williams Digital Photography 2 09-16-2003 03:02 PM
Re: Pixel size of individual Pixel Tom Thackrey Digital Photography 2 09-14-2003 04:17 PM
Hot pixel vs. stuck pixel Abrasha Digital Photography 5 09-02-2003 04:49 PM



Advertisments