highlighting word in JPEG image



Hi,

I have JPEG-images which present pages from an original text document. The original paper documents are OCR-ed and in the output of the OCR I get the coordinates of every word. The user of my application will be able to search for text and the search results will be presented as a JPEG of the page, with the word the user searched for highlighted.

At the moment I'm experimenting with the highlighting of the text. I
tried the following (see code below), but I'm not really sure I'm on the
right track.
- Has anyone suggestions for a better approach?
- I saw some examples with ByteLookupTables. Would that be a better solution for highlighting?
- I'm a bit worried about the performance. Any ideas on that?
- The version I post below has a color problem. I fiddled with the
AlphaComposite value, but the original JPEG is either too dark or too
pale compared to the orginal.
- The coordinates are from Prime Recognition OCR-software. They say:
"the coordinates are in BMU units. One BMU is 1/1200 of an inch". Trial
and error with an example showed me that dividing their coordinates by
4 gave me the right coordinates for the word in Java. Would this always
be correct or is there a more universal way of converting the OCR-coordinates to Java-coordinates? I read somewhere that Java coordinates are 72 units (pixels) per inch, so I can't understand how my division by 4 can give me the right result, but it does :-)


Any help will be greatly appreciated!
Kind regards,
Marian

marian dot hellema at kb dot nl


My code below ============================================================

import java.awt.*;
import java.awt.event.*;
import java.awt.color.*;
import com.sun.image.codec.jpeg.*;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.awt.geom.GeneralPath;
import java.io.*;
import javax.swing.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.net.*;
import javax.imageio.*;
import javax.imageio.stream.*;

public class Test{
  public static void main(String[] args) throws IOException {

    Image img = Toolkit.getDefaultToolkit().getImage("00002.jpg");
    JFrame f = new JFrame("Proef");
    try {
      MediaTracker tracker = new MediaTracker(f);
      tracker.addImage(img, 0);
                tracker.waitForID(0);
    } catch (Exception e) {}


// width and height hard-coded for the time being int width = 1000; int height = 1000;

    BufferedImage bi = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
    Graphics2D biContext = bi.createGraphics();

biContext.clearRect(0, 0, width, height);
AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.9f);
biContext.setComposite(ac);


    biContext.drawImage(img, new AffineTransform(), null);

    biContext.setColor(new Color(255, 255, 121));
          // yellow color for the highlighted text


biContext.fillRect(456/4, 2752/4, (888-456)/4, (2880-2752)/4); // coordinates hard-coded for the time being // coordinates from OCR are 456, 888, 2752, 2880 // division by 4 gives the Java coordinates

    biContext.dispose();

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(new JLabel(new ImageIcon(bi)));
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);

  }

}


====================================================== End of code

.