| Reply | « Previous Thread | Next Thread » |
|
Hello.
I hava a array byte [] with a image that I need to convert to greyscale. How can I do it? |
|
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 |
|
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
|
| sivakumar.a |
| View Public Profile |
| Find all posts by sivakumar.a |
|
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! |
|
-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; |
| simonhayles |
| View Public Profile |
| Find all posts by simonhayles |
|
Ohhh, Ok!
It´s very interesting. I´ll try it. Thanls. |
|
But ... one more question:
What´s the size of byte [] and int [] arrays (for the image)? it´s the same? Thanks |
|
1 int = 4 bytes
|
| simonhayles |
| View Public Profile |
| Find all posts by simonhayles |
|
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 |
|
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. |
|
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 |
|
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 |
| ruffshuvit |
| View Public Profile |
| Find all posts by ruffshuvit |
|
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); Cheers, Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
wow...you are rocks man...i'll try now and post the result later...
thanks a lot!!..:) |
| ruffshuvit |
| View Public Profile |
| Find all posts by ruffshuvit |
|
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? |
| ruffshuvit |
| View Public Profile |
| Find all posts by ruffshuvit |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| 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 |