简体   繁体   English

图像处理

[英]image processing

I want to change the value of the pixels in an image, for which i need to store the image as a matrix. 我想更改图像中像素的值,我需要将图像存储为矩阵。 How can i perform this job? 我怎么能完成这份工作? Please guide. 请指导。

BufferedImage image = ImageIO.read(..);
image.setRGB(x, y, rgb);

Check the documentation of BufferedImage 查看BufferedImage的文档

Using image.setRGB is extremely slow. 使用image.setRGB非常慢。

You can use Catalano Framework 您可以使用Catalano Framework

Example: 例:

FastBitmap fb = new FastBitmap(bufferedImage);

int x = fb.getRed(0,0);

//If you prefer to retrieve the matrix you can do too.
int[][][] image = new int[fb.getHeight][fb.getWidth][3];
fb.toArrayRGB(image);

Firstly read the image into a BufferedImage. 首先将图像读入BufferedImage。

BufferedImage image = ImageIO.read(new File("..."));

Then create matrix like structure in the 2D array like this and set RGB: 然后像这样在2D数组中创建矩阵状结构并设置RGB:

for(int i = 0; i < image.getWidth(); i++){
   for(int j = 0; j < image.getHeight(); j++){
     image.setRGB(i, j, rgb);  
   } 
}
  • Image is 2d representation of data (pixel info) 图像是数据的2d表示(像素信息)

  • 2D means x&y directions. 2D表示x和y方向。 In case of image, these directions are generally treated as rows & columns 在图像的情况下,这些方向通常被视为行和列

  • To change the pixel value, we have to get its location in these rows and columns 要更改像素值,我们必须在这些行和列中获取其位置

  • Getting pixel location is like that class teacher addressing the unknown student with his sitting position (ex:2nd bench 3rd person) 获得像素位置就像那位班级老师用他的坐姿来解决这位未知学生(例如:第2工作室第3人)

  • Like this we have to address the pixel by its rows and column location 像这样,我们必须通过行和列位置来处理像素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM