Monochrome grayscale image, get the intensity of a pixel

℡╲_俬逩灬. 提交于 2019-12-02 11:06:15

问题


I'm attempting to derive an intensity value for a particular pixel in a monochrome "grayscale" image. I have some pseudocode, but thus far I've been unable to implement something that really works.

/**
 * Retrieve the intensity value at location ('row', 'column') of the image 'img' and return it
 * Note: 
 * - the 2D image is stored as an 8bit, 1D, row-major array of type byte
 * - the data type byte is signed in Java
 * - Slide 27 of chapter 2 introduces the representation of an image
 * @param img in row major format
 * @param row to evaluate
 * @param column to evaluate
 * @param width of img
 * @param height of img
 * @return the intensity value at row and column if within bounds, -1 otherwise
 */
public int getIntensityValue(byte[] img, int row, int column, int width, int height) {

       int intensity = img[row,column];

       return intensity;
}

回答1:


Maybe this will help you:

http://docs.oracle.com/javase/7/docs/api/java/awt/image/BufferedImage.html

http://docs.oracle.com/javase/7/docs/api/javax/imageio/ImageIO.html

BufferedImage img = ImageIO.read(new File("filePath.png"));

int sRbgColor = img.getRGB(int x, int y);

Color c = new Color(sRbgColor);
int red = c.getRed();
int green = c.getGreen();
int blue = c.getBlue();

If it's monochrome, then red green and blue should be equal.



来源:https://stackoverflow.com/questions/18758218/monochrome-grayscale-image-get-the-intensity-of-a-pixel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!