You Are Here:

Community: Developer Discussion Boards

Reply « Previous Thread | Next Thread »

#1 Old How to convert to greyscale a Image. Help. - 2006-01-26, 18:44

Join Date: Sep 2005
Posts: 15
Location: SPAIN
padules's Avatar
padules
Offline
Registered User
Hello.
I hava a array byte [] with a image that I need to convert to greyscale.

How can I do it?
Reply With Quote

#2 Old Re: How to convert to greyscale a Image. Help. - 2006-01-27, 12:06

Join Date: Mar 2005
Posts: 499
Location: Paris
njzk2
Offline
Regular Contributor
1/ how do you store a rgb (you have a rgb image at first, don't you ?) in a byte[] ?
usually, it is a int[] -- which is also what you get with Image.getRGB()

2/ basically, each greyscale pixel is the mean of the 3 colors (r+g+b / 3) of the pixel, but practically, it is usual to modify the weight of each color (more blue, if i remember)

3/ if you have an int[], each int is one pixel. an int is 4 bytes, divided in : alpha, red, green, blue, one byte each.
so for each pixel in your int[], you get each component via a modulo and division (for example red = int / (256*256) % 256), make the sum, and then the last division

4/ if you definitly have a byte[], then probably each byte[3*i] is red, byte[3*i + 1] is green and each byte[3*i + 2] is blue, but the idea stays the same
Reply With Quote

#3 Old Re: How to convert to greyscale a Image. Help. - 2006-01-27, 12:08

Join Date: Jan 2006
Posts: 3
sivakumar.a
Offline
Registered User
It is based on the BMP format you have taken ,For example if you have 24 bpp 8 bytes is taken for R,G,B values to store ,when you want to convert that to Gray scale the 255 colors should be mapped to gray scale i.e in terms of 127 gray color data ,it is monochrome then 1 bit .. so you can check out that in microsoft site for various pattern
Reply With Quote

#4 Old Re: How to convert to greyscale a Image. Help. - 2006-01-27, 21:10

Join Date: Sep 2005
Posts: 15
Location: SPAIN
padules's Avatar
padules
Offline
Registered User
I have a image in a byte [], that I have obtained the a capture of the mobile camera

(....)
byte [] byteImage = VideoControl.getSnapshot("encoding=bmp);
Image img= Image.createImage(byteImage, 0, byteImage.length);

And yes, with img.RGB (...) I can obtained a int [], but the values are strange (-11448240, for example). How can I obtain the Red, Blue and Green component?

Thanks!
Reply With Quote

#5 Old Re: How to convert to greyscale a Image. Help. - 2006-01-27, 21:56

Join Date: Aug 2005
Posts: 29
simonhayles
Offline
Registered User
-11448240 in hex is 0xFF515050 and the colour format is 0xAARRGGBB.
so;

int colour=0xFF515050;
int alpha = (colour>>24)&0xff;
int red = (colour>>16)&0xff;
int green = (colour>>8)&0xff;
int blue = colour&0xff;
Reply With Quote

#6 Old Re: How to convert to greyscale a Image. Help. - 2006-01-28, 10:35

Join Date: Sep 2005
Posts: 15
Location: SPAIN
padules's Avatar
padules
Offline
Registered User
Ohhh, Ok!

It´s very interesting. I´ll try it.

Thanls.
Reply With Quote

#7 Old Re: How to convert to greyscale a Image. Help. - 2006-02-14, 12:21

Join Date: Sep 2005
Posts: 15
Location: SPAIN
padules's Avatar
padules
Offline
Registered User
But ... one more question:

What´s the size of byte [] and int [] arrays (for the image)? it´s the same?


Thanks
Reply With Quote

#8 Old Re: How to convert to greyscale a Image. Help. - 2006-02-14, 12:24

Join Date: Aug 2005
Posts: 29
simonhayles
Offline
Registered User
1 int = 4 bytes
Reply With Quote

#9 Old Re: How to convert to greyscale a Image. Help. - 2006-02-14, 12:27

Join Date: Mar 2005
Posts: 499
Location: Paris
njzk2
Offline
Regular Contributor
logically no ...
considering that an int contains 4 informations (red, blue, green and alpha) at the same time, and a byte contains only on of these, the ratio between int[].length and byte[].length should be 4

however, the byte[] you obtain with your getSnapshot is a bmp, i.e. not purely colors data : it contains at least (it don't know perfectly the format of a bmp, but i think it's something like that) a header, the letters B, M, and P
Reply With Quote

#10 Old Re: How to convert to greyscale a Image. Help. - 2006-02-14, 13:25

Join Date: Sep 2005
Posts: 15
Location: SPAIN
padules's Avatar
padules
Offline
Registered User
ok, ok. I didn´t know about the header image, but I think it´s correctly. All images are thier properly structure.

So ... I need to pass x byte, where x is the byte of the header. Isn´t it?
And, nobody know if this method is not implemented already?

Thanks.
Reply With Quote

#11 Old Re: How to convert to greyscale a Image. Help. - 2006-02-14, 15:49

Join Date: Mar 2005
Posts: 499
Location: Paris
njzk2
Offline
Regular Contributor
afaics, x is something like 36.
but then, the alpha byte is at the end, regrouped
so for a 2 pixels img, you have:
36 bytes, r1 g1 b1 r2 g2 b2 a1 a2
but if you are in 256 colors, its another problem, and it's different for any format of bmp.
my suggestion is you create your image with you byte[]
then you get the int[], you create a similar array with grey levels instead of colors, then you re create an image from this array.
i the most reliable solution i can think of
Reply With Quote

#12 Old Unhappy Re: How to convert to greyscale a Image. Help. - 2009-03-02, 16:25

Join Date: Feb 2009
Posts: 4
ruffshuvit
Offline
Registered User
hello...

i really need a help here..can someone provide me with code example on how to convert image in byte[] to gray...because im really blur with juz the expalnation.. i have search a code example in the net, but dunno how to related it with my code...can someone guide me....i have taken a snapshot using byte[] raw = mVideoControl.getSnapshot(null);..

and here the code example that i search in the net:

public BufferedImage toGray(BufferedImage bi)
{
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
ColorConvertOp op = new ColorConvertOp(cs, null);

return op.filter(bi, null);
}


If got another way to do this, please provide to me...really hope someone can help...thanks
Reply With Quote

#13 Old Re: How to convert to greyscale a Image. Help. - 2009-03-02, 18:04

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
That's J2SE code, and is no use to you at all.

By coincidence, I posted some code for converting an Image to greyscale just the other day.

You'll need to convert your byte[] to an Image first. Try:

Code:
Image colourImage = Image.createImage(raw, 0, raw.length);
Hope this helps.

Cheers,
Graham.
Reply With Quote

#14 Old Talking Re: How to convert to greyscale a Image. Help. - 2009-03-02, 20:20

Join Date: Feb 2009
Posts: 4
ruffshuvit
Offline
Registered User
wow...you are rocks man...i'll try now and post the result later...
thanks a lot!!..:)
Reply With Quote

#15 Old Cool Re: How to convert to greyscale a Image. Help. - 2009-03-02, 22:06

Join Date: Feb 2009
Posts: 4
ruffshuvit
Offline
Registered User
Nice dude...now i can convert to grey image..:)

but i have 1 problem now...how do i save the image that i converted?
because before this i used

outStream.write(imageData)
where imageData is in byte[] type.

If i used the same method, it will result an error message because byte[] has been converted to Image type. Is there any other way to save it?..or i need to converted back to byte[] type?
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

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

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Convert Binary Data(sent in XML file) to an image file dtripathy General Symbian C++ 9 2009-07-07 16:36
--- ???save image problem??? --- ferenn Mobile Java Media (Graphics & Sounds) 6 2007-10-01 15:33
How to convert image into PDU format pdeolasee Smart Messaging 4 2006-06-14 07:53
HELP: Mutable Image to Immutable Image? rj_cybersilver Mobile Java Media (Graphics & Sounds) 1 2005-03-26 10:58
saving jpeg image on grid list flicker82 General Symbian C++ 0 2005-01-21 05:22

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d18645X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtopicQUqfnTopicZmediaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ