Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Debugging of pixelData and grayScale

 
Mohksin Rashid
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok..the classes r working..but im not sure how to intergrate the 2 methods together..can someone help? and must i do it offscreen? or is there another way..no.1 i haf 2 extract the pixelData and then change it to grayScale..and then look at the grayscale value..separating the white(255) from the rest of the image..assuming the background(white) is not want..therefore, extracting juz the image..so i need help in integrating the 2 methods below:-

public 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
//return pixelData;
}catch(Exception e){
//throw new Exception("Cannot get pixel values from Image.");
}finally{

}
return pixelData;
}

public 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;
}
}
 
Punit Raizada
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I think if you just call the methods it should do the trick

Here capturedImage is a javax.microedition.lcdui.Image object that refers to the image you want to process


Now grayPixels contains grayscale values of the image. The size of grayPixels is [capturedImage.getHeight() * capturedImage.getWidth()].

Now to read the grayScale data to weed out the white use for loops.


In the If condition you might want to check for a value greater than 200 if you are indeed looking for the background that can be white.. again this depends on your input image.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic