Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table clipper functionality (norma-0.7.0-alpha) and supporting analysis code #2

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions misc/hocr.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http://kba.github.io/hocr-spec/1.2/
24 changes: 15 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
<modelVersion>4.0.0</modelVersion>

<properties>
<imageanalysis.version>1.1.0</imageanalysis.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- upstream -->
<html.version>2.1.0</html.version>
<cproject.version>0.7.0-SNAPSHOT</cproject.version>
<boofcv-io.version>0.17</boofcv-io.version>
<boofcv-feature.version>0.17</boofcv-feature.version>
<boofcv-visualize.version>0.17</boofcv-visualize.version>
<imgscalr-lib.version>4.2</imgscalr-lib.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>


<groupId>org.contentmine</groupId>
<artifactId>imageanalysis</artifactId>
<version>${imageanalysis.version}</version>
<version>1.3.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ImageAnalysis</name>
<description> Image analysis and IO routines </description>
Expand All @@ -26,29 +32,29 @@
<dependencies>
<dependency>
<groupId>org.contentmine</groupId>
<artifactId>html</artifactId>
<version>${html.version}</version>
<artifactId>cproject</artifactId>
<version>${cproject.version}</version>
</dependency>
<dependency>
<groupId>org.boofcv</groupId>
<artifactId>io</artifactId>
<version>0.17</version>
<version>${boofcv-io.version}</version>
</dependency>
<dependency>
<groupId>org.boofcv</groupId>
<artifactId>feature</artifactId>
<version>0.17</version>
<version>${boofcv-feature.version}</version>
</dependency>
<dependency>
<groupId>org.boofcv</groupId>
<artifactId>visualize</artifactId>
<version>0.17</version>
<version>${boofcv-visualize.version}</version>
</dependency>

<dependency>
<groupId>org.imgscalr</groupId>
<artifactId>imgscalr-lib</artifactId>
<version>4.2</version>
<version>${imgscalr-lib.version}</version>
</dependency>

</dependencies>
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/org/xmlcml/image/ImageProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,23 @@

import org.apache.commons.io.FilenameUtils;
import org.apache.log4j.Logger;
import org.xmlcml.graphics.image.ImageIOUtil;
import org.junit.Assert;
import org.junit.Test;
import org.xmlcml.graphics.svg.SVGG;
import org.xmlcml.graphics.svg.SVGSVG;
import org.xmlcml.graphics.svg.util.ImageIOUtil;
import org.xmlcml.image.colour.ColorAnalyzer;
import org.xmlcml.image.colour.ColorUtilities;
import org.xmlcml.image.pixel.MainPixelProcessor;
import org.xmlcml.image.pixel.PixelEdge;
import org.xmlcml.image.pixel.PixelEdgeList;
import org.xmlcml.image.pixel.PixelGraph;
import org.xmlcml.image.pixel.PixelIsland;
import org.xmlcml.image.pixel.PixelIslandList;
import org.xmlcml.image.pixel.PixelList;
import org.xmlcml.image.pixel.PixelNodeList;
import org.xmlcml.image.pixel.PixelRingList;
import org.xmlcml.image.pixel.PixelSegmentList;
import org.xmlcml.image.processing.Thinning;
import org.xmlcml.image.processing.ZhangSuenThinning;
import org.xmlcml.image.slice.XSlice;
Expand Down Expand Up @@ -264,7 +273,7 @@ public static ImageProcessor createDefaultProcessorAndProcess(File imageFile) {
if (imageFile == null) {
throw new RuntimeException("null image file");
} else if (!imageFile.exists()) {
throw new RuntimeException("Cfile does not exist " + imageFile);
throw new RuntimeException("file does not exist " + imageFile);
} else if (imageFile.isDirectory()) {
throw new RuntimeException("File is directory " + imageFile);
} else {
Expand Down Expand Up @@ -603,4 +612,5 @@ public BufferedImage getBinarizedImage() {
public BufferedImage getThinnedImage() {
return thinnedImage;
}

}
21 changes: 16 additions & 5 deletions src/main/java/org/xmlcml/image/ImageUtil.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package org.xmlcml.image;

import java.awt.Color;

import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.FileOutputStream;

import javax.imageio.ImageIO;

import org.apache.commons.io.FilenameUtils;
import org.apache.log4j.Logger;
import org.imgscalr.Scalr;
import org.imgscalr.Scalr.Method;
Expand Down Expand Up @@ -497,5 +494,19 @@ public static String debugRGB(int rgb) {
int[] channels = ImageUtil.getRGBChannels(rgb);
return "r="+channels[RED]+",g="+channels[GREEN]+",b="+channels[BLUE];
}

/** deep copy image.
*
* thanks to https://stackoverflow.com/questions/3514158/how-do-you-clone-a-bufferedimage
*
* @param bi input image
* @return deep copy
*/
public static BufferedImage deepCopy(BufferedImage bi) {
ColorModel cm = bi.getColorModel();
boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
WritableRaster raster = bi.copyData(null);
return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
}

}
8 changes: 4 additions & 4 deletions src/main/java/org/xmlcml/image/SVGGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import org.xmlcml.euclid.Real2;
import org.xmlcml.euclid.Real2Range;
import org.xmlcml.euclid.Transform2;
import org.xmlcml.graphics.html.HtmlElement;
import org.xmlcml.graphics.html.HtmlFactory;
import org.xmlcml.graphics.html.HtmlSpan;
import org.xmlcml.graphics.html.util.HtmlUtil;
import org.xmlcml.graphics.svg.SVGG;
import org.xmlcml.graphics.svg.SVGSVG;
import org.xmlcml.graphics.svg.SVGText;
import org.xmlcml.html.HtmlElement;
import org.xmlcml.html.HtmlFactory;
import org.xmlcml.html.HtmlSpan;
import org.xmlcml.html.util.HtmlUtil;


public class SVGGenerator {
Expand Down
Loading