Sign in to follow this  
Mary Coory

[java] image into smaller images

Recommended Posts


public class MyImage {

private java.awt.Image;
private String[] myWords;

}


Sorry =D

If you have to recognize the words out of a image you haven't created, then it is beyond me. There is a Java API for OCR that might help, but I never tried it out.

Rodrigo

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I think his point is that it won't be trivial AT ALL to recognize where the spaces are in an image.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
I think his point is that it won't be trivial AT ALL to recognize where the spaces are in an image.


but the spaces between the words in the image can be controlled. aren't it?

Share this post


Link to post
Share on other sites
The point is, do you want to split up ANY image who has text? If that is the case, then you're up to a HUGE challenge that certainly includes optical character recognition.

But if you have to split up only the images that YOU create through your application, you could simply store an array of possible words of that image, and implement methods that would draw them togheter and also separately.

If you specify which you are trying to achieve, maybe people can point out better solutions ;)

Son Of Cain
(Geez, I have posted my name up there =)

Share this post


Link to post
Share on other sites

Hello Rodrigo ;)

I have to split up ONLY the images that I created through my application. but I need to cut the original image into the sub-images. the method you mentioned will not be suitable here since I want to deal just with images not with array.

Thanks,

Share this post


Link to post
Share on other sites
Still, you are left with a image only, which does not help so much.
My suggested approach is this:



import java.awt.Image;
import java.util.List;
import java.util.ArrayList;

// import Image IO auxiliary classes

public class ImageWithWords {

private Image myImage;
private List < String > words;

public ImageWithWords(List < String > words) {
this.words = words;
myImage = drawWholeImage();
}

public Image drawWholeImage() {
for (String word : words) {
// For each word on the list, calculate the space
// left for drawing (if you have a specific size limit)
// and customize the drawing
}
}

public Image[] drawSeparately() {
for (String word : words) {
// Draw a Image for each word
}
}

// Checks wether this Image has the given word
public boolean containsWord(String word) {
return words.contains(word);
}

}




There are plenty of optimizations to add, concerning better usability. But if all you're trying to do is a means of authentication for the web, I'm sure there are other approaches better suited for the task. Can't tell for sure if that's what you want, since we are on a Game development forum =D

Son Of Cain

Share this post


Link to post
Share on other sites
Hello

Sorry in being late.

I do my best to understand your suggested approach Son of Cain !

If you explain more, I' apprciated

I add the follwing image for more clarification :

Here is the complete image:
http://nomatterwhat.jeeran.com/words.JPG

Here are the images of the words contained in the orginal image
http://nomatterwhat.jeeran.com/first.JPG
http://nomatterwhat.jeeran.com/second.JPG

Hope this will help

Share this post


Link to post
Share on other sites
Well, so you have a "pattern" to build images. I assume so if you are going to use such a grid to "draw" your words. If that is the case, you have yet another solution for the matter at hand. It still is composed of the concept "draw separately" / "draw as a whole", though.

The only change is that a word is composed by many grid blocks. Each block is either "full" (black) or "empty" (white). By the proper combination of blocks, you have a word.

So you begin by creating a Block class, with the boolean state of full/empty, and other methods you might find useful. Also, the Block class should have draw() method that returns either a black or white rectangle.

Next, you create a Word class, which is composed by a matrix of Block objects. The Word class has a method to draw itself. This method simply iterates through the Blocks, get their rectangle and draw them, or return something (maybe another rectangle) to be drawn by our next class.

Last, you have your own CustomImage class, composed of many Word objetcs, that know how to draw themselves. CustomImage is responsible for drawing all the words in a proper order, and also, give information about which words it contains (exactly what you want to achieve).

I hope I am not saying anything stupid ;) In that case, someone here will surely aid you better than I.

Son Of Cain

Share this post


Link to post
Share on other sites

Hello Son of Cain,

I think what you said is the algorithem I wnt to apply, but with grid I mean the pixel of the image. My Image is binary-level image with black pixel (part of a word) , and white pixel ( part of a background). sorry for not mention that preivously.

I will go throgh your method carfully and come back with questions ;).

Thanks :)

Share this post


Link to post
Share on other sites
Yes, a "pixel" can be a Line2D, a Point2D, or anything you choose to represent a pixel as an object. There is no "Pixel" class you can use, so that's why I threw in the rectangle example, assuming you had a larger grid.

But you seem to get the concept of it. But remember that this is something I came up with after a few seconds of thought - there's probably something better to apply here, or at least there are some pitfalls you should be careful of.

Cya
Son Of Cain

Share this post


Link to post
Share on other sites
your image took forever to load, but it is quite simple of a task, if we make three assumptions: letters are seperated by one pixel, words are seperated by two pixels, all words are on one line (this last one isn't that important, we could even generallize disregarding it).


BufferedImage img = /* however you get your image */;

int[] pixColComp = new int[img.getWidth()];
//calculate column composite values
for(int x=0;x<img.getWidth();++x){
pixColComp[x]=0;
for(int y=0;y<img.getHeight();++y){
if(img.getRGB(x, y) == 0){
++pixColComp[x];
}
}
}

ArrayList<Integer> splitCols = new ArrayList<Integer>();

for(int i = 0; i < pixColComp.length; ++i){
if(pixColComp[i] > 0){
splitCols.add(i-1);
}
}

int blank_counter = 0;
for(int i = 0; i < pixColComp.length; ++i){
if(pixColComp[i]==0){
++blank_counter;
}
if(blank_counter == 2){
splitCols.add(i-1);
blank_counter = 0;
}
}

for(int i=pixColComp.length - 1; i >= 0; --i){
if(pixColComp[i] > 0){
splitCols.add(i+1);
}
}

BufferedImage[] splitUpImages = new BufferdImage[splitCols.getSize()-1];
for(int i = 0; i < splitCols.getSize()-1; ++i){
int x1 = splitCols.get(i);
int x2 = splitCols.get(i+1);
int width = x2-x1;
int height = img.getHeight();
splitUpImages[i] = new BufferdImage(width, height, BufferedImage.TYPE_INT_RGBA);
int[] temp = new int[width * height];
img.getRGB(x1, 0, width, height, temp, 0, 1);
splitUpImages[i].setRGB(0,0,width, height, temp, 0, 1);
}



[Edited by - capn_midnight on June 6, 2005 7:32:29 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this