简体   繁体   English

从图像中将单个像素读入矩阵

[英]Reading individual pixels into matrix from an Image

I am working on a character recognition project using neural.networks.我正在使用 neural.networks 进行字符识别项目。 My first objective is to read those pixels from image where i found any alphabets.我的第一个目标是从我发现任何字母的图像中读取那些像素。 I mean if there are three alphabets in an image A, B and C at random places, how i will read the pixel values of A, B and C and store them in matrix?我的意思是,如果图像 A、B 和 C 中随机出现三个字母,我将如何读取 A、B 和 C 的像素值并将它们存储在矩阵中?

The question isn't very clear.问题不是很清楚。 If you mean that you have image files like A.png, B.png etc. and you want the pixel values in a matrix, you can create an RBG matrix in matlab with如果你的意思是你有像 A.png、B.png 等图像文件,并且你想要矩阵中的像素值,你可以在 matlab 中创建一个 RBG 矩阵

image = imread('A.png');

This will give you a width-height-3 matrix of RGB values.这将为您提供 RGB 值的 width-height-3 矩阵。


Thanks for the link to the image, let's try again: :-)感谢您提供图片链接,让我们再试一次::-)

So, assuming you don't want to manually say where each character is, we'll have to find them automatically.因此,假设您不想手动说出每个角色的位置,我们将不得不自动找到它们。 To do this, let's convert to black&white, then use bwconncomp to find the pixels of each letter.为此,让我们转换为黑白,然后使用bwconncomp查找每个字母的像素。

image = imread('A.png');
ibw = im2bw(image);
C = bwconncomp(image);
boxes = regionprops(C, 'BoundingBox');
letters = cell{26};
for i=1:26
  %get left, top, width, height from boxes(i).BoundingBox
  %I'm not on matlab at the moment, so I don't know exactly how to
  %but it should be quite easy.
  letters{i} = image(left:left+width, top:top+height, :);
end

After we find connected components, we get their bounding box using regionprops and put each bounding box in a separate image.找到连接的组件后,我们使用regionprops获取它们的边界框,并将每个边界框放在单独的图像中。

You can do:你可以做:

imageA=imread('imageA.jpg');
pixel1=imageA(y,x,:);

When using Java, you can first load the image as a BufferedImage:使用 Java 时,您可以先将图像加载为 BufferedImage:

BufferedImage image = ImageIO.read(imageUrl);

And then you can get the individual pixel RGB values with:然后您可以通过以下方式获得各个像素的 RGB 值:

image.getRGB(x, y);

You can also use Color object to parse RGB integer value into individual color code.您还可以使用 Color object 将 RGB integer 值解析为单独的颜色代码。

Color color = new Color(image.getRGB(x,y));
int red = color.getRed();
int green = color.getGreen();
int blue = color.getBlue();

From this point onward you can do pretty much anything you want.从这一点开始,你几乎可以做任何你想做的事。 I've worked with the same thing in the past.我过去曾处理过同样的事情。 My recommendation is that you shouldn't make the search space too large by using all the color.我的建议是您不应该通过使用所有颜色使搜索空间太大。 Black and white will do also in the beginning.黑色和白色也可以在开始时使用。

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

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