Java image normalization - java

I am doing the image processing and I am interested in normalization of the image. Somewhere I come to know about the ImageJ library.
So could anyone help me in finding example code for Image normalization using ImageJ library.

I know It isn't with imageJ. But I would help you with java.
Try to use Catalano Framework.
The next version (1.2) will have more algorithms for image normalization as:
Gray World
White Patch
Modified White Patch
Example:
FastBitmap fb = new FastBitmap(bufferedImage);
HistogramEqualization hist = new HistogramEqualization();
hist.applyInPlace(fb);
bufferedImage = fb.toBufferedImage();

Related

Reading text from image using Tesseract and OpenCV (Java)

I'm trying to make a program that can read the information off of a nutritional label but Tesseract is having lots of issues actually being able to read anything. I've tried a number of different Image processing techniques using OpenCV but not much seems to help.
Here are some of my better looking attempts (which happen to be the simplest):
Tango bottle label uneditied
Tango bottle label edited
Output:
200k], Saturates, 09
Irn Bru bottle label unedited
Irn Bru bottle label edited
Output
This is just changing the images to grey scale, a 3x3 Gaussian blur and Otsu binarisation.
I would appreciate any help on how to make the text more readable using OpenCV or any other image processing library.
Would it be simpler to forego using Tesseract and use machine learning for this?
First of all read this StackOverflow Answer regarding OCR prepossessing.
The most important steps described above are the Image Binarization and Image Denoising
Here is an example:
Original Image
Grey Scale
Unsharp Masking
Binarization
Now ready to apply OCR
JAVA code
Imgproc.cvtColor(original, grey, Imgproc.COLOR_RGB2GRAY, 0);
Imgproc.GaussianBlur(grey, blur, new Size(0, 0), 3);
Core.addWeighted(blur, 1.5, unsharp, -0.5, 0, unsharp);
Imgproc.threshold(unsharp,binary,127,255,Imgproc.THRESH_BINARY);
MatOfInt params = new MatOfInt(Imgcodecs.CV_IMWRITE_PNG_COMPRESSION);
File ocrImage = new File("ocrImage.png");
Imgcodecs.imwrite(ocrImage,binary,params);
/*initialize OCR ...*/
lept.PIX image = pixRead(ocrImage);
api.SetImage(image);
String ocrOutput = api.GetUTF8Text();

How to resize imageicon with same quality

I`m currently making an application to manage other application on windows.
when i resize the icon it change quality
i`m getting icon by this code
ShellFolder shell = ShellFolder.getShellFolder(new File(load1.getString("Path")));
image = shell.getIcon(true);
And when i resize it it change the quality.
My resize code is
sIMG = image.getScaledInstance(45, 45, Image.SCALE_AREA_AVERAGING);
What i want to do to keep the quality of the icon.
Please help.
I'm assuming you want to re-size your icon to look the same no matter what size you change it to. Regular images will are composed of pixels therefore lost of quality is inevitable.
When I did a web design project at my school I learned about Vector images(.svg).
Summary Of Vector Vs Bitmap http://etc.usf.edu/techease/win/images/what-is-the-difference-between-bitmap-and-vector-images/
Of course anyone please correct me if I'm wrong but I think vectors is the only way you can achieve your goal assuming that I'm understanding your question. Vector image quality does not change much or at all on re-size.
Java doesn't natively support Vector Images but follow this tutorial and you should achieve your goal. (It's not really a tutorial more like copy and paste)
http://plindenbaum.blogspot.com/2009/07/simple-java-based-svg-renderer.html
Also this link will let you convert your existing images to SVG
http://vectormagic.com/home
(you get 2 downloads when you sign up) There are other tools to convert to SVG but this was the quickest solution I could find. If you're good with Photoshop I think I saw some tutorials for it but don't quote me on that.
I hope this is what you were looking for best of luck to.
you can resize any image by the following code.
$thumb = new Imagick();
$thumb->readImage('myimage.gif'); $thumb->resizeImage(320,240,Imagick::FILTER_LANCZOS,1);
$thumb->writeImage('mythumb.gif');
$thumb->clear();
$thumb->destroy();
For more information please go to the following link.
resize image
resize optimized image

How to detect faces with jviolajones library?

I'm trying count faces in the picture with jviolajones library. I want to do this in pure Java with no extra dependencies so OpenCV is not an option. My code is like:
detector.getFaces("filePath", 1.2f,1.1f,.05f, 2,true);
I've tried haarcascade_frontalface_alt and haarcascade_frontalface_default from OpenCV. But results are bad about 5 pictures recognized good for 30 tested.
I've tried adjust parameters but it didn't help. Any suggestion for better results, or maybe another library. I was wondering, maybe I have to prepare pictures before detecting faces?
This works:
detector.getFaces("filePath", 1.2f,1.1f,.05f, 2,true);
But I had to scaled my photos to 640x480 and transform them to gray, this works with haarcascade_frontalface_default.xml classifier from OpenCV.

how to perform the image segmentation in java?

hi guys i am an infant for image processing technique in java , i have decided to develop one project in image processing so i need what are the algorithms are followed and also which one is easier to develop please some one guide me it may be great for me.....and also which technology is best for image processing java or Matlab? guide me...
I think the best image processing tool for you depends on the kind of project you're working on.
If you're working on a research project that needs productivity, quick validation and writting reports, Matlab and similar tools are the best option. On the other hand, if you're developing a software product, Java, C++, C, Objective-C, etc is more indicated. Matlab solutions are not easy to deliver and maintain in production.
Since you asked how to do image segmentation in Java, I'll provide an example using Java and Marvin Image Processing Framework. As suggested by #Asif Sharif, FloodFill segmentation is a good strategy and I used it!
INPUT IMAGE:
OUTPUT IMAGE:
HOW IT WORKS:
Load input image.
Change green pixels to white pixels.
Apply intensity thresholding for separating foreground from background.
Apply morphological closing to group separated parts of the same object
Use FloodFill segmentation to get the segments.
Draw the segments coordinates in the original image.
SOURCE:
import static marvin.MarvinPluginCollection.*;
public class SimpleSegmentation {
public SimpleSegmentation(){
// 1. Load image
MarvinImage original = MarvinImageIO.loadImage("./res/robocup.jpg");
MarvinImage image = original.clone();
// 2. Change green pixels to white
filterGreen(image);
// 3. Use threshold to separate foreground and background.
MarvinImage bin = MarvinColorModelConverter.rgbToBinary(image, 127);
// 4. Morphological closing to group separated parts of the same object
morphologicalClosing(bin.clone(), bin, MarvinMath.getTrueMatrix(30, 30));
// 5. Use Floodfill segmention to get image segments
image = MarvinColorModelConverter.binaryToRgb(bin);
MarvinSegment[] segments = floodfillSegmentation(image);
// 6. Show the segments in the original image
for(int i=1; i<segments.length; i++){
MarvinSegment seg = segments[i];
original.drawRect(seg.x1, seg.y1, seg.width, seg.height, Color.yellow);
original.drawRect(seg.x1+1, seg.y1+1, seg.width, seg.height, Color.yellow);
}
MarvinImageIO.saveImage(original, "./res/robocup_segmented.png");
}
private void filterGreen(MarvinImage image){
int r,g,b;
for(int y=0; y<image.getHeight(); y++){
for(int x=0; x<image.getWidth(); x++){
r = image.getIntComponent0(x, y);
g = image.getIntComponent1(x, y);
b = image.getIntComponent2(x, y);
if(g > r*1.5 && g > b*1.5){
image.setIntColor(x, y, 255,255,255);
}}}
}
public static void main(String[] args) { new SimpleSegmentation(); }
}
For image segmentation in JAVA you can also consider to use open-source IMMI tool (http://spl.utko.feec.vutbr.cz/en/). In comparison to Matlab, it is (in my opinion) more simple to use and simply enables also image mining.
You can use the Java Advanced Imaging (JAI) Library to do image processing in java. You have to decide for yourself whether Java or MATLAB is better for you.
Algorithm for Image segmentation depends upon what type of output you want after segmentation. Each algorithm performs a different segmentation. I think the region growing or Flood Fill is good for this purpose.
You can use Java/JAI and JavaCV for this Image processing tasks.
MATLAB is better for image processing. And the best way is to find special image processing tools (or libraries).

An easy way (tool?) to compare images pixel for pixel in different formats?

Well I've written a basic lossless jpeg joiner thing in java now but I'd like to compare the files it produces with the original files.
I can only compare so much in a hex editor, does anyone know of an easy way, software or java based (preferably software as I dont feel like any more coding for now!) that I can compare two images and produce a "difference map" of where the pixels aren't the same?
Thanks.
Thanks for the suggestions.
I tried the Gimp approach first which works well except when the difference between the images are very small. I couldn't find an "enhance differences" option to make the differences obvious and the histogram also only gives a rough representation of the differences.
In the end I used ImageMagick something I'd installed a while ago and forgot all about. Creating a difference/comparison image is as easy as typing:
compare first.jpg second.png difference.gif
in the command line.
It's all nicely explained here.
TortoiseIDiff is a free image diff viewer:
http://tortoisesvn.tigris.org/TortoiseIDiff.html
It is part of TortoiseSVN, but can be used without Subversion.
Depending on your project, not all files which are under version
control are text files. Most likely you will have images too, for
example screenshots and diagrams for the documentation/helpfile.
For those files it's not possible to use a common file diff tool,
because they only work with text files and diff line-by-line. Here is
where the Tortoise Image Diff tool (TortoiseIDiff) comes to the
rescue. It can show two images side-by-side, or even show the images
over each other alpha blended.
You could do a lot worse than Perceptual Diff.
The best approach would be to use Pix for windows (comes with the DirectX SDK). Supports Bitmap, PNG and Jpeg...Enjoy!
Use an image editor like Photoshop or the Gimp or whatever, which has multiple layers. Create an image where each source image in a separate layer.
At this point, you can visually compare the images by toggling the top layer's visibility off and on.
In most decent editors, you can also set the top layer to "difference" mode. Now each image pixel's value is the absolute difference of the pixel values in the underlying images. You can use e.g. a histogram tool to see if the images are identical. If they're identical, then all the pixel values will be exactly 0.
For stuff like this, I love the netpbm/pbmplus toolkit. You can use djpeg and pnmtoplainpnm to convert each image into a simple ASCII format. You then just read both files and emit a new image which shows where pixels differ. You could, for example, compute the Euclidean distance in RGB space between old and new pixels and emit a white pixel for zero difference, light gray for a small difference, darker for larger differences, and so on. The ASCII format is simple and is well documented on the man pages, and all the standard viewer programs can view it directly.
The latest version of Araxis Merge will do image diffs ( http://www.araxis.com/merge/topic_comparing_image_files.html ).
Unfortunately it's not a free app so whether or not you're willing to pay for it is another thing...
There's also a convenient web app called Resemble.js, which analyzes and compares images pixel by pixel. The different pixels in the images (if any) are highlighted with pink or yellow color depending on your preference.

Categories