Search in sources :

Example 21 with Shape

use of com.joliciel.jochre.graphics.Shape in project jochre by urieli.

the class ChupchikLowerRightFeature method checkInternal.

@Override
public FeatureResult<Boolean> checkInternal(ShapeWrapper shapeWrapper, RuntimeEnvironment env) {
    Shape shape = shapeWrapper.getShape();
    int xSectors = 11;
    int centreSectors = 13;
    int marginSectors = 1;
    double[][] grid = shape.getBrightnessBySection(xSectors, centreSectors, marginSectors, SectionBrightnessMeasurementMethod.RELATIVE_TO_MAX_SECTION);
    double minChupchikStart = 8;
    boolean foundChupchik = false;
    for (int j = grid[0].length - 1; j >= grid[0].length - 5; j--) {
        boolean foundBlack = false;
        int chupchikSize = 0;
        for (int i = grid.length - 1; i > 0; i--) {
            if (!foundBlack && i < minChupchikStart)
                break;
            if (grid[i][j] >= 0.5) {
                foundBlack = true;
                chupchikSize++;
            } else if (grid[i][j] < 0.5 && foundBlack) {
                break;
            }
        }
        if (LOG.isTraceEnabled())
            LOG.trace("Row " + j + ", chupchickSize: " + chupchikSize);
        if (foundBlack && chupchikSize <= 3) {
            foundChupchik = true;
            break;
        } else if (foundBlack) {
            break;
        }
    }
    FeatureResult<Boolean> outcome = this.generateResult(foundChupchik);
    return outcome;
}
Also used : Shape(com.joliciel.jochre.graphics.Shape)

Example 22 with Shape

use of com.joliciel.jochre.graphics.Shape in project jochre by urieli.

the class EmptySectorsBinaryFeature method checkInternal.

@Override
public FeatureResult<Boolean> checkInternal(ShapeWrapper shapeWrapper, RuntimeEnvironment env) {
    Shape shape = shapeWrapper.getShape();
    double[][] totals = shape.getBrightnessBySection(5, 5, 1, SectionBrightnessMeasurementMethod.RAW);
    Mean testMean = new Mean();
    Mean otherMean = new Mean();
    for (int i = 0; i < totals.length; i++) {
        for (int j = 0; j < totals[0].length; j++) {
            double brightness = totals[i][j];
            if (testSectors[i][j])
                testMean.increment(brightness);
            else if (brightness > shape.getBrightnessMeanBySection(5, 5, 1, SectionBrightnessMeasurementMethod.RAW))
                otherMean.increment(brightness);
        }
    }
    double testMeanValue = testMean.getResult();
    double otherMeanValue = otherMean.getResult();
    if (LOG.isDebugEnabled())
        LOG.trace("Test mean: " + testMeanValue + " (* threshold = " + testMeanValue * THRESHOLD + "), Other mean: " + otherMeanValue);
    boolean result = (testMeanValue * THRESHOLD < otherMeanValue);
    FeatureResult<Boolean> outcome = this.generateResult(result);
    return outcome;
}
Also used : Mean(org.apache.commons.math.stat.descriptive.moment.Mean) Shape(com.joliciel.jochre.graphics.Shape)

Example 23 with Shape

use of com.joliciel.jochre.graphics.Shape in project jochre by urieli.

the class FixTextWindowController method onClick$btnOK.

@Listen("onClick = #btnOK")
public void onClick$btnOK(Event event) {
    // TODO: replacing all occurrences of the same word on the line instead
    // of just the current one
    LOG.debug("onClick$btnOK");
    winFixText.setVisible(false);
    String rowText = (String) winFixText.getAttribute(FixTextWindowController.ATTR_ROW_TEXT);
    Textbox rowTextBox = (Textbox) winFixText.getAttribute(FixTextWindowController.ATTR_ROW_TEXTBOX);
    LetterLabelUpdater updater = (LetterLabelUpdater) winFixText.getAttribute(FixTextWindowController.ATTR_LETTER_UPDATER);
    GroupOfShapes group = (GroupOfShapes) winFixText.getAttribute(FixTextWindowController.ATTR_GROUP);
    group.setSkip(chkSkip.isChecked());
    group.setHardHyphen(chkHardHyphen.isChecked());
    group.setBrokenWord(chkBrokenWord.isChecked());
    group.setSegmentationProblem(chkSegmentProblem.isChecked());
    group.save();
    List<Textbox> letterBoxes = new ArrayList<Textbox>();
    for (Object child : letterBoxRow.getChildren()) {
        if (child instanceof Textbox) {
            letterBoxes.add((Textbox) child);
        }
    }
    StringBuilder sb = new StringBuilder();
    // for (Textbox letterBox : letterBoxes) {
    for (Shape shape : group.getShapes()) {
        Textbox letterBox = (Textbox) letterBoxRow.getFellow("FixTextLetterBox_" + shape.getId());
        String letter = letterBox.getText();
        String newLetter = ImageController.getLetterForDisplay(letter);
        LOG.debug("Letter: " + letter + ", newLetter: " + newLetter);
        sb.append(newLetter);
    }
    LOG.debug(sb.toString());
    String newText = rowText.replace(FixTextWindowController.ROW_TEXT_PLACE_HOLDER, sb.toString());
    rowTextBox.setText(newText);
    updater.updateLetterLabels();
}
Also used : Shape(com.joliciel.jochre.graphics.Shape) GroupOfShapes(com.joliciel.jochre.graphics.GroupOfShapes) Textbox(org.zkoss.zul.Textbox) ArrayList(java.util.ArrayList) LetterLabelUpdater(com.joliciel.jochre.web.ImageController.LetterLabelUpdater) Listen(org.zkoss.zk.ui.select.annotation.Listen)

Example 24 with Shape

use of com.joliciel.jochre.graphics.Shape in project jochre by urieli.

the class Jochre method doCommandLogImage.

/**
 * Log a shape's image to the log file, to make sure it got segmented and stored
 * correctly.
 */
public void doCommandLogImage(int shapeId) {
    // correctly
    if (shapeId > 0) {
        GraphicsDao graphicsDao = GraphicsDao.getInstance(jochreSession);
        Shape shape = graphicsDao.loadShape(shapeId);
        shape.writeImageToLog();
        LOG.debug("Letter: " + shape.getLetter());
    }
}
Also used : Shape(com.joliciel.jochre.graphics.Shape) GraphicsDao(com.joliciel.jochre.graphics.GraphicsDao)

Example 25 with Shape

use of com.joliciel.jochre.graphics.Shape in project jochre by urieli.

the class Jochre method doCommandTestFeature.

/**
 * Test a feature on a particular shape.
 */
public void doCommandTestFeature(int shapeId) {
    // just a utility for testing a feature on a particular shape
    ShapeFeature<?> feature = new VerticalElongationFeature();
    GraphicsDao graphicsDao = GraphicsDao.getInstance(jochreSession);
    if (shapeId > 0) {
        Shape shape = graphicsDao.loadShape(shapeId);
        shape.writeImageToLog();
        RuntimeEnvironment env = new RuntimeEnvironment();
        feature.check(shape, env);
    } else {
        // String result = "false";
        // TrainingServiceLocator trainingServiceLocator =
        // locator.getTrainingServiceLocator();
        // TrainingService trainingService =
        // trainingServiceLocator.getTrainingService();
        // List<Integer> shapeIds =
        // trainingService.findShapesForFeature("ג", feature, result);
        List<Integer> shapeIds = graphicsDao.findShapeIds("—");
        Map<Object, Integer> outcomeMap = new HashMap<>();
        for (int oneShapeId : shapeIds) {
            Shape shape = graphicsDao.loadShape(oneShapeId);
            shape.writeImageToLog();
            RuntimeEnvironment env = new RuntimeEnvironment();
            FeatureResult<?> weightedOutcome = feature.check(shape, env);
            Object outcome = weightedOutcome.getOutcome();
            Integer count = outcomeMap.get(outcome);
            if (count == null)
                outcomeMap.put(outcome, 1);
            else
                outcomeMap.put(outcome, count.intValue() + 1);
        }
        LOG.debug("Outcomes:");
        for (Object outcome : outcomeMap.keySet()) {
            LOG.debug("Outcome " + outcome.toString() + ", count " + outcomeMap.get(outcome));
        }
    }
}
Also used : Shape(com.joliciel.jochre.graphics.Shape) RuntimeEnvironment(com.joliciel.talismane.machineLearning.features.RuntimeEnvironment) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) GraphicsDao(com.joliciel.jochre.graphics.GraphicsDao) VerticalElongationFeature(com.joliciel.jochre.graphics.features.VerticalElongationFeature)

Aggregations

Shape (com.joliciel.jochre.graphics.Shape)74 ArrayList (java.util.ArrayList)22 GroupOfShapes (com.joliciel.jochre.graphics.GroupOfShapes)14 JochreImage (com.joliciel.jochre.graphics.JochreImage)13 Paragraph (com.joliciel.jochre.graphics.Paragraph)9 RowOfShapes (com.joliciel.jochre.graphics.RowOfShapes)9 Decision (com.joliciel.talismane.machineLearning.Decision)8 Test (org.junit.Test)8 JochreSession (com.joliciel.jochre.JochreSession)7 JochrePage (com.joliciel.jochre.doc.JochrePage)7 Config (com.typesafe.config.Config)7 TreeSet (java.util.TreeSet)7 JochreDocument (com.joliciel.jochre.doc.JochreDocument)6 BufferedImage (java.awt.image.BufferedImage)6 ShapeInSequence (com.joliciel.jochre.boundaries.ShapeInSequence)5 ShapeSequence (com.joliciel.jochre.boundaries.ShapeSequence)5 GraphicsDao (com.joliciel.jochre.graphics.GraphicsDao)5 RuntimeEnvironment (com.joliciel.talismane.machineLearning.features.RuntimeEnvironment)5 SplitFeature (com.joliciel.jochre.boundaries.features.SplitFeature)4 JochreException (com.joliciel.jochre.utils.JochreException)4