# [java] image into smaller images

This topic is 4825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi everybody I need to do the following: given image contains words in English. I want to get every word in separte image. Any help?

##### Share on other sites
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 on other sites

Hi Rodrigo,

I'm not talking about image recognition here. The idea is just to cut the image which contains several words into smaller images each of them contains one word.

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

##### Share on other sites
Quote:
 Original post by Anonymous PosterI 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 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 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 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 classespublic 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 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 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

1. 1
2. 2
JoeJ
20
3. 3
frob
20
4. 4
5. 5

• 10
• 11
• 12
• 13
• 9
• ### Forum Statistics

• Total Topics
632211
• Total Posts
3004818

×