aspose file tools*
The moose likes Java Micro Edition and the fly likes getRGB method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "getRGB method" Watch "getRGB method" New topic
Author

getRGB method

Mohksin Rashid
Greenhorn

Joined: Jun 28, 2004
Posts: 13
hi all..ok..i need help regarding my J2ME project..its a sch project...i am to compare the color pixels and if there is a huge contrast between one pixel and the next pixel,i should b able to draw an outline of the similar pixel..basically..its about detecting a white based background and a person in the picture..how can i detect the edge of the person..and extract it out and put it over a background..i understand that it is possible by using getRGB method but im dunno how 2 implement it.anyone can help? any sample codings? and does anyone know how the pixel comparison start? for example, top left hand to bottom right? im not sure..anyone?


-J2ME-
Punit Raizada
Ranch Hand

Joined: Mar 20, 2004
Posts: 156
Hi,

Iam not sure if i got your question right but if you are looking to get edges in the image and get a outline ....

> You convert the image into grayscale.
> White will be near 255 ... any darker colors will be towards 0
> to get the edges just take a threshold value and divide the pixels into data ( not white) and non data(white) regions. Plot the image again and you should see th eoutline of the data.

Let me know if this is what u were looking for... if it is then i will send you some code snippets of how to go about doing this.


SCJP 1.4
Everything that can go wrong will go wrong -Murphy
Mohksin Rashid
Greenhorn

Joined: Jun 28, 2004
Posts: 13
hi, yes..that is what i am trying to do..to detect the outline..the method u suggested i didnt thought of it.thx! it sounds workable..but i dont understand the part when u say "to get the edges just take a threshold value and divide the pixels into data ( not white) and non data(white) regions"..hmm..can u further elaborate? thx for the help once again!
Punit Raizada
Ranch Hand

Joined: Mar 20, 2004
Posts: 156
Hi,

I think you already figured out how to get the pixel data from a Image Object and then get grayscale values. I assume you are using the formula (r+g+b) /3. It is not the best but it does work. This should give you the values for each pixel between 0 to 256.

Now, I assume the background is white and the data whose outline u wish to draw is non-white. I havent seen your data but i would suggest the following approach for edge detection. This is a basic approach and does not invlove hough transforms etc..
1) Find the max and min of pixel values.
2) Find the average pixel value ..something like (max+min)/2
3) Anything below the average (threshold value) is data and anything above is background.
4) I believe this will give u regions of data in the image and then you can plot the outline.

Now, this aprroach is not really the best approach to be using for the image returned by the camera on a cellphone. You will have to run soem trial tests on your data and adjust the formula for calculating the threshold value accordingly.

Good luck.. seems to be an interesting project.

Two methods ---
1) Get image data .. calls the getRGB() method of the image to return an int array with ARGB values
int[] getPixelData(Image capturedImage)throws Exception{
//Initialise the array to return
int[] pixelData = new int[capturedImage.getHeight() * capturedImage.getWidth()];
int pOffset = 0;
int pScanLength = capturedImage.getWidth();
try{
//Get the RGB array
capturedImage.getRGB(pixelData, pOffset, pScanLength, 0, 0, capturedImage.getWidth(), capturedImage.getHeight());
//pixelData has the ARGB values of the Image
}catch(Exception e){
throw new Exception("Cannot get pixel values from Image.");
}finally{
/*@- Nothing to clean up here@@*/
}
return pixelData;
}

2) Calculate the Grayscale values. Pass the int[] array with ARGB data to this method. Returns a int[] with values between 0 and 256

int[] getGrayData(int[] imageARGBData)throws Exception{
int[] grayData = new int[imageARGBData.length];
//parse through the input array
int grayValue = 255;
for( int j= (imageARGBData.length -1); j >= 0 ; j--){
//(r + g + b)/3
grayValue = (((imageARGBData[j] >> 16) & 0x00FF) +((imageARGBData[j] >> 8) & 0x0000FF) + (imageARGBData[j] & 0x000000FF));
grayValue = grayValue / 3;
grayData[j] = grayValue ;
}
return grayData;
}
Mohksin Rashid
Greenhorn

Joined: Jun 28, 2004
Posts: 13
hey..thanks a million dude..ill inform u if it works! =) thx once again..
Punit Raizada
Ranch Hand

Joined: Mar 20, 2004
Posts: 156
Hope it works ..:-)... atleast you are working on a intresting project ;-)
jun estropigan
Greenhorn

Joined: Jul 25, 2010
Posts: 7
hi to all !! is it possible to blur image real time in j2me?? and does anyone have any sample codes of image blurring?? thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

Jun,

Welcome to the JavaRanch. But, please! don't wake the zombies!. Any thread that old the people who were on it have probably moved on to other jobs already. Just start your own thread, instead.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
Consider Paul's rocket mass heater.
 
subject: getRGB method