Comparing Bitmap Pixel Data To BufferedImage?

Mar 21, 2015

I'm working on a project based on Roger Alsing's Mona Lisa evolution.

My problem seems to be that when I compare the RGB values of the target image and the randomly generated image, I don't get a representative result of how "close" the two images are.

I load the target image (a 24-bit bitmap) using:

img = ImageIO.read(new File(filePath));

I draw onto a BufferedImage with:

for(int i = 0; i < numPolys*12; i += 12){
p[(int)(i/12)].addPoint(gene[i], gene[i+1]);
p[(int)(i/12)].addPoint(gene[i+2], gene[i+3]);
p[(int)(i/12)].addPoint(gene[i+4], gene[i+5]);
p[(int)(i/12)].addPoint(gene[i+6], gene[i+7]);
Color mycol = new Color(gene[i+8], gene[i+9], gene[i+10], gene[i+11]);
gf.setColor(mycol);
gf.fillPolygon(p[(int)(i/12)]);
}

And I compare the BufferedImage with the target image using:

for(int x = 0; x < inGene.x; ++x){
for(int y = 0; y < inGene.y; ++y){
Color mycol1 = new Color(exp.getRGB(x, y));
Color mycol2 = new Color(inImage.getRGB(x, y));
int delta = mycol1.getRed() - mycol2.getRed();
score += (delta * delta);
delta = mycol1.getGreen() - mycol2.getGreen();
score += (delta * delta);
delta = mycol1.getBlue() - mycol2.getBlue();
score += (delta * delta);
}
}

My problem is that my code runs to a certain point, where it seems no matter what happens to the image, it doesn't seem to get any closer to the target image.

View Replies


ADVERTISEMENT

BufferedImage Or Pixel Arrays

Jun 30, 2014

I am making a 2d game engine and i was wonder is it better to use BufferedImages and subImages to store/render sprites from sprite sheets or use BufferedImages and store it in a pixel array and then manipulate the pixel array to do what you want.

Basically is loading in BufferedImage and getting the tile of the sprite sheet with subImages better than loading in a BufferedImage and then putting the data in a pixel array and making a new array with the part of the BufferedImage you want.what i have been told the BufferedImage and subImage use more of the graphics card and the pixel array method uses more of the processor.

View Replies View Related

Converting 1x1 Pixel To 3x3 Pixel

Nov 17, 2014

this code that I've constructed?

//Setting the size of the graphics window
final int WINDOW_DIMENSION = 200;
EasyGraphics generate = new EasyGraphics(WINDOW_DIMENSION,WINDOW_DIMENSION);
 
[Code].....

What I would like to do is to convert the 200x200 picture to a 600x600 graphic window. Currently, my code is structured in such a way that it zooms into the 200x200 display by a factor of 3.

View Replies View Related

Comparing String Data?

Jan 27, 2015

This program accepts Student ID numbers, Name, and grade point average. The problem I am having is with the if else statement that compares id to studentID[x]. I have tried to compare using if(id.equals(studentID[x])) and also I have tried using if(id == (studentID[x])) as shown in the code below. I keep getting incorrect results though.

//FILE: StudentIDArray.java 
import javax.swing.*; //Used for the JOption dialog boxes
import java.util.*; //Used for Scanner input

[Code]....

View Replies View Related

Comparing Data Across Different Database Programmatically?

Oct 22, 2014

I am looking to reconcile data between SQL server and Oracle DB post the migration, I need to verify the data (rows/columns) for last 10 years, Before i start writing a Java Utility to accomplish this, My question is are there any existing libraries or API which can accomplish the same ....

View Replies View Related

How To Load Bitmap Image In Android

Apr 23, 2014

I have been trying to draw a bitmap image onto the canvas from Android and all it displays is a blank white screen. Whenever my app starts up, I am calling this in my game - view class which extends View and overrides the onDraw method:

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

[Code] ....

View Replies View Related

Some Pixel Manipulation

Oct 25, 2014

I currently have an on going project of making a gameengine and am currently doing a lighting engine. How to create simple algorithm of explain to me the concepts of creating a algorthm to do a task, like explain how to get the hue saturation and brightness. This preferably needs to be done in java for me to copy the code but as long as i have a concept to go by I could probably translate the code over so it's not to much of a problem.

View Replies View Related

Another Java Pixel Manipulation

Nov 21, 2014

I have a jpeg that I need to print a border around. My plan was to take the jpeg and throw it on top of a second image that is a few pixels bigger in each direction. Currently, my code prints the image with a white border on the right and bottom sides. Is there a way to print the border on all sides, and maybe even make it a more distinct color? I am not allowed to use graphics. I can only manipulate pixels. Here is the basis of my code.

public class MyArt
{
private Picture image;
/**
* Create an Art object using the jpg or bmp at the indicated location
*/
public MyArt(String filename)
{
image = new Picture(filename);

[code]....

View Replies View Related

BufferedImage Has White Padding On Top?

Jul 27, 2014

What I am doing is loading a new image from resources in my project, so that I can get the size. Using this, I create a new BufferedImage with those dimensions. The following code is what I am using to take the original BufferedImage, and scale it.

Java Code:

public ImageIcon getBackImage(){
before = new BufferedImage((int)img.getWidth(null), (int)img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
int w = before.getWidth();
int h = before.getHeight();
try{
URL url = getClass().getResource("/Blue_Back.png");
before = ImageIO.read(url);

[Code] ......

The scaling seems to be working fine, but what I have noticed is a line of approximately 10 pixels at the top of the image. I took the original image and blew it up to ensure that I wasn't just enlarging undesired portions and this wasn't the case. I then tried to fetch a subImage of the BufferedImage, and that also left the padding at the top. Is there something I am missing that is placing this undesired padding at the top of my bufferedImages ?

View Replies View Related

IndexColorModel 255 Colors To BufferedImage

Apr 4, 2014

I need to write an image to a .png with a 255-color indexed color model. I know usually do it like this: Java Code: BufferedImage img=new BufferedImage(width,height,BufferedImage.TYPE_BYTE_INDEXED,model); mh_sh_highlight_all('java'); but that doesn't work with models with 255 colors (as opposed to 256 colors). I'm fairly sure it is the BufferedImage creation that is the problem, as when I call model.getMapSize(), it returns the correct size.

The extra color added to the image's index is 15,15,15.

Should I be something other than a BufferedImage to write the image, or should I be using a different constructor for BufferedImage, or am I doing something else wrong?

View Replies View Related

BufferedImage Auto Rotate JPG

Apr 11, 2015

I need my Java program (I'm working in Eclipse if it matters) to detect if an image is a portrait or a landscape, but since i am directly downloading them from my camera they only have it written somewhere in metadata, the image width and height is the same for landscape and portrait. I have the rotation code and the rest of the program working, but I need to somehow get a variable (for example integer one) to tell me if it is a portrait or a landscape image. I tried getting to the metadata but my Eclipse decided that import com.drew.metadata.Metadata; cannot be resolved.

BufferedImage image = ImageIO.read(new File(imagePath, imageName)); and after I get the variable "orientation" it looks like this

int orientation = ???;
BufferedImage newImage = oldImage;
if (orientation>1){
newImage = rotate(oldImage);
}

View Replies View Related

JavaFX 2.0 :: BufferedImage To Mat - OpenCV

Mar 16, 2015

I am new to JavaFX and OpenCV. The Problem is, that JavaFX can't handle Mat objects. First I load an image as a BufferedImage. Then i have to convert this to Mat. Do my image Processing with OpenCV and again convert the result image to a BufferedImage to display in on my UI. Here are the methods for converting Buff to Mat and Mat to Buff I found on the internet:
 
public static Mat img2Mat(BufferedImage image)
    {
  byte[] data = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
  Mat mat = new Mat(image.getHeight(), image.getWidth(), CvType.CV_8UC3);
  mat.put(0, 0, data);
  return mat;

[Code] ....
 
Next I do some OpenCV stuff:
 
public static BufferedImage hello(BufferedImage img) {  
  Mat source  = img2Mat(img); //Convert Buff to Mat
  BufferedImage outImg = null;
       try{
          System.loadLibrary( Core.NATIVE_LIBRARY_NAME );

[Code] ....
 
Finally I call the hello method in my controller:
 
void menuItemTestFired(ActionEvent event) {  
    try {
              result = ImageProc.hallo(bImage);//bImage is an image I've loaded before.
              imageView.setImage(SwingFXUtils.toFXImage(result, null));

[Code] .....
 
Unfortunately I get a lot of errors. Here are the first one:
 
Caused by: java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat(III)J
  at org.opencv.core.Mat.n_Mat(Native Method)
  at org.opencv.core.Mat.<init>(Mat.java:471)
 
[Code] ....
 
Can't figure out why this doesn't work. -.-

View Replies View Related

How To Get Pixel Values Of Image And Store It Into Array

Nov 13, 2014

So i wanted to try something new like find an image within an image. So for my "find" method I would like to take an image and use it to scan and compare sum of absolute differences with the bigger image. So that the smallest SAD would be the exact image that I am using to scan. What I am thinking is to put each pixel value of both images into two separate arrays and compare them via Math.abs(image1[i][j]-image2[i][j]); . My only problem is that I do not know how to put each pixel value into an array.

Also, If I only want to compare just the green in the picture. I saw that the Pixel class has a getGreen(); method. If I want to find the SAD of the green, would Math.abs(image1.getGreen()-image2.getGreen()); work? I was planning to have 2 nested loops running through each column and row for each image and just find the SAD of the green value.

View Replies View Related

Pixel Manipulation - Create Art Object Using JPG Or BMP At Indicated Location

Nov 20, 2014

I am working on a project using pictures and am having some trouble. My assignment is to take a jpeg, and reflect it(over an imaginary x-axis so to speak). As this is my first time working with images, I am very lost. My approach was to take "pixel 0" and have it swap places with "pixel max". Theoretically, I believe I would only need to do this for the first 50% of the pixels, as each flip works on 2 opposite pixels. With my code thus far (the reflect() method), I print the left half of the image. Note: I must use pixel manipulation. I cannot use graphics.

public class MyArt
{
private Picture image;

/**
* Create an Art object using the jpg or bmp at the indicated location
*/
public MyArt(String filename)
{
image = new Picture(filename);

[Code] .....

View Replies View Related

Rendering Images Of Type BufferedImage - Pixels Are Not Consistent In Size

Jun 26, 2014

As implied by the title, when I am rendering images of the type "BufferedImage" unto a Swing application, the images' pixels are not consistent in size. Some might be larger than other, and some might be smaller than other.

Here is a screenshot of what I am talking about (you might need to zoom in a bit because the image is so small): [URL] ....

And here is also some code for you. The images are actually from a sprite sheet, which I first load in its entirety and then split up in an array.

Java Code:

public static BufferedImage sprites[];
...
public void loadSprites(){
try{
BufferedImage bigImage = ImageIO.read(new File("SOURCE/BLA/BLA/THIS/IS/ACTUALLY/NOT/THE/REAL/SOURCE/IN/CASE/YOU'RE/WONDERING/I/JUST/DON'T/WANT/YOU/TO/FIND/ME/AND/RAPE/ME"));
sprites = new BufferedImage[16 * 16];

[Code] ....

So, how do I make the pixels equally small?

View Replies View Related

Swing/AWT/SWT :: Double Drawing Pixels When Manipulating DataBuffer Of BufferedImage

Feb 9, 2014

I've been working my way through a tutorial to build a simple 2D tile-based engine that also allows the code to manipulate the colour of pixels on the screen based on a monochrome map read from a file. I've got the code right line for line, but I seem to have a bug when it comes to draw to the screen! At regular intervals, despite what is held in the pixel array of ints (which I have confirmed to be correct when debugging), I get the same row of pixels being draw twice in a row. I figured there was some loop issue somewhere, but after attempting to debug this for some time, I haven't come up with the answer.

Original tilesheet:As rendered:

Game.java:
package igg.engine.game;
import igg.engine.game.gfx.Screen;
import igg.engine.game.gfx.SpriteSheet;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;

[Code] ....

View Replies View Related

Comparing Two Variables

Mar 30, 2014

Let's get it out of the way -- I'm stumped. On something that should be pretty simple to solve. Code follows.

public class Sum {
public static void main(String [] args) {
Double nSum = 0.0;
Double aDouble = 100.0;
for (int i = 0; i < 1000; i++){
nSum += 0.1;

[Code] ....

The output:

100.000000
100.000000
false
false
false
false
false

Process finished with exit code 0

I wrote another simple program and hardcoded the values: aDouble = 100.0; bDouble= 100.0000

Using aDouble.equals(bDouble) returns true, just as one would expect.

So what am I overlooking?

View Replies View Related

Comparing Two Hashmaps

Mar 3, 2015

I have a simple question but I dont understand why I am getting false for this boolean statement.

System.out.println("hash compare " + (trialSearch.returnHash() == fish.returnHash()));
System.out.println("fish.returnHash()" + (fish.returnHash()));
System.out.println("trialSearch.returnHash()" + (trialSearch.returnHash()));

the output is as follow:

hash compare false
fish.returnHash(){T=[1, 2, 3, 5], G=[], A=[0], C=[4]}
trialSearch.returnHash(){T=[1, 2, 3, 5], G=[], A=[0], C=[4]}

why is it printing false for the boolean statment when the two hashmaps contain the same values and keys?

View Replies View Related

Comparing First Name Of Two People

Nov 6, 2013

I'm trying to create an algorithm that compares the first names of two people, which goes ahead and cancels similar characters and then counts the remaining characters to give a 0 if the remaining characters are even and a 1 if the remaining characters odd.

View Replies View Related

Comparing Lengths On Strings

Apr 25, 2015

I am making a program i want String length and compare it that it will be null or not but it gives me error.

View Replies View Related

Comparing 2 String Values?

Nov 8, 2014

I am trying some exercises on codingbat.com, and am stuck at the following program.

"Given a string, return true if it ends in "ly"."

With the following lines, if I type a print command instead of return, I get "ly". Yet if I aks to compare the result (which is "ly" as I can see with a print command) with == "ly", I get false?

What I also don't get, is that if I tye the programs in javascript, in that language the program works.

String str = "Oddly"
return ((str.substring(str.length()-2))== "ly");
}

View Replies View Related

Comparing And Cloning Objects?

Aug 2, 2014

I'm working on a program with the following instructions: Write a class named Octagon that extends GeometricObject and implements the Comparable and Cloneable interfaces. Assume that all 8 sides of the octagon are of equal size. The area can be computed using the following formula

area = (2 + 4/square root of 2) * side * side

Write a program (driver) to read in a series of values from a file, display the area and perimeter, create a clone and compare the object and its clone (based on the area). In addition, your program should compare the current object (just read in) with the first object read in. The program ends when a negative number is read from the file.

My GeometricObject abstract class:

public abstract class GeometricObject {
public abstract double getArea();
public abstract double getPerimeter();
}

My Octagon Class:

public class Octagon extends GeometricObject implements Comparable<Octagon> {
private double side = 1.0;
protected native Object clone() throws CloneNotSupportedException;
public Octagon() {
}
public Octagon(double side) {
super();

[code]....

As you can tell, I've still got a long way to go in the tester class but this is where I'm running into some difficulties.

You'll notice that in the return statement of the toString method in the Octagon class, I put a ? after the "Clone Compare:" portion of the code, what should go here. I've never worked with either the Comparable or Cloneable interfaces before.

How I should create my objects in a way that would give the following sample output.

Object 1: Area: 120.71
Perimeter: 40.0
Clone Compare: Equal
First Compare: Equal

Object 2: Area: 271.60
Perimeter: 60.0
Clone Compare: Equal
First Compare: First is smaller

View Replies View Related

Comparing Words In Same Line

Jan 24, 2015

I have tried to compare word in same line..instally i divided words using split...after that my move got stopped....

View Replies View Related

Error Comparing Strings

May 24, 2014

I was writing a code to have the library books classified in name, author, area, ed, etc. I'm using NetBeans and it doesn't accuse any error. But when I run the project, it never goes right and shows the books only in one area, regarthless what I type. (The goal of the algorithm is to separate the books in areas (sciences, humanities and biological science).

View Replies View Related

Comparing String But /0 Keeps Being Counted

Apr 20, 2014

Ok I am trying to compare a string to see if all characters are unique. If there is a library for this or a better way to approach this do tell. However I find it important to understand what is going on behind the scenes. The issue is that the program counts the spaces '/0' and therefore everything will never be unique.

public class CheckUnique
{
private String sentence = "This will be compard";
private char[] checker;
private String isUnique = "The sentence is unique";
private String notUnique = "The sentence is not unique";
 
[code]...

View Replies View Related

Comparing In A Two Dimensional Array?

May 3, 2014

I have to make a program in which users inputs a number and the program should search into a two dimensional array and print out all the values that are below the number This is my first time experimenting with 2D Arrays and how to do this program I have the array set up

String firstarray[][]=
{{"", "Store101", "Store102", "Store103", "Store104"},
{"Tennis Shoes", "102", "54", "20", "78"},
{"Sweaters", "45", "25", "35", "75"},
{"Jeans", "12", "35", "45", "65"},
{"Shorts", "54", "25", "34", "45"},
{"Jackets", "15", "35", "50", "25"}
};

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved