简体   繁体   中英

Reading individual pixels into matrix from an Image

I am working on a character recognition project using 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?

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

image = imread('A.png');

This will give you a width-height-3 matrix of RGB values.


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.

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.

You can do:

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

When using Java, you can first load the image as a BufferedImage:

BufferedImage image = ImageIO.read(imageUrl);

And then you can get the individual pixel RGB values with:

image.getRGB(x, y);

You can also use Color object to parse RGB integer value into individual color code.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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