Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Tuesday, October 13, 2009

Image recognition with java tool


Neuroph is an opensource tool collection for java, and as you can get from its name, it uses neural networks. In the future, we may use it in one of our sideprojects.
Here is an online demo:
You can get an overview here:
Of course the source code is available, and it's worth checking, if you're really into neural networks.

Saturday, September 12, 2009

Logo II.


This is my next try:
However, I'm not satisfied with that... I simply wanted to be it a little bit less linear, but now it looks falling apart. The double border around seems departed now.

Being short of time, I'll only upload the differences in the code.

Now I'm using this line, to determine the difference horizontally:
int diffWidth = Math.min(i, width - i - 1)/2;
This implies, that the gradient will be somewhat smaller horizontally than vertically. (Half of it..)
A small problem with this is, that it doubles width of the vertical borderlines. I'll fix that next week, it's not that cool now.

The other change was, the nonlinearity.

Instead of the modulo function, now I'm using a whole new function to determine, what heights will be grey:
if(isGrey(diffMin)) grey = true;
which is equal to:
grey = isGrey(diffMin);

And the function is:
public static boolean isGrey(int diff)
{
int counter = 6;
int sum = counter;
while(sum <= diff)
{
if(sum == diff)return true;
counter+=4;
sum += counter;
}
return false;
}

Well, the small problem with this is, that it computes every possible height every time. It's not a big deal, since it runs in a few milliseconds, but it would be faster, if I first create a HashSet of integer values, put in the first few values (in this case: 6, 13, 21, 30, 40, 51, 62, ...), and search in that HashSet every time. Maybe I'll do that later.
(However, that would be better even because I could set the heights of the lines manually, without writing an algorithm. For such a small application it would be maybe better.)

Okay, that's it for now, I'll come with a new logo next week.

Sunday, September 6, 2009

Messing with our new logo

I'm trying to create a new background for the header of our blog.
You can see the current result here:


It looks quite nice, like the countour-map of a long pyramid-like structure.

This is how I created this one: (in lack of 1337 photoshop sk1lls:)

I created a 24-bit bmp, with the width of 640 and height of 96. I needed this only to create the 54 byte header of my bmp file, so this actual bmp file was blank white. (This file has been saved as 'start.bmp'.)
In this small piece of java code the header will be copied to 'end.bmp':

Reader r = new FileReader("start640.bmp");
BufferedReader br = new BufferedReader(r);
char[] cbuf = new char[256];
int l = 54;
br.read(cbuf, 0, l);
br.close();
FileWriter fw = new FileWriter("end.bmp");
fw.write(cbuf, 0, l);

(Be aware, that file operations need to be in a try-catch block!)
After this, with my brand new FileWriter, I'll continue to fill up the contents of my bmp file. To do that, we need to know, that each pixel will need 3 bytes there, the so called RGB-code. In our case these 3 bytes will be equal, since we need grey lines.

First we have to put down the bottom line pixels, then the above, and so on, until reaching the top. To create the contour, I used a really simple algorithm: first I compute the distance from the border, and I'll color every seventh line, or 'height'. (Just like in a contour-map.)
This is the code:

int width = 640;
int height = 96;

for(int j = 0; j != height; j++)
{
for(int i = 0; i != width; i++)
{
boolean grey = false;

int diffHeight = Math.min(j, height - j - 1);
int diffWidth = Math.min(i, width - i - 1);

int diffMin = Math.min(diffHeight, diffWidth);

if(diffMin % 7 == 2) grey = true;

char colour = 255;

if(grey)colour = 210;
cbuf[0] = colour; cbuf[1] = colour; cbuf[2] = colour;
fw.write(cbuf, 0, 3);
}
}
fw.close();

Simple, isn't it?

When I'll have the time, I'll try to improve the look of this stuff by using a non-linear function, or by random terrain.

(By the way after setting the code color to blue, I was not able to use the line:
for(int i=0; i {smallerthan} max; i++){} // where {smallerthan} means that sign
cause there were some html errors with the styles. How comes this, google?!
I had to modify the 'less than' sign to 'not equals',
and I'm not able to modify the color of the above line...)

Wednesday, November 26, 2008

sincx

Just created this image for testing some edge detection algorithms:

And, if I'm there already, I will check out some image processing techniques using the sinc function. ( sin(x)/x )
These kind of images should fit perfectly for that purpose, cause they have information in the frequency domain.




Sunday, November 9, 2008

setLayout(null);

Somehow, I dont like to use the built in layout managers in Java.
So, when I started to write a little project lately, I've been using code blocks like this:
resetButton = new Button("Reset");
resetButton.setBounds(440, 400, 100, 40);
resetButton.addActionListener(this);
add(resetButton);
However, the last button I've added went fullscreen.
(Or full-background, since the others remained visible.)

I remember, two or three years ago I spent an hour debugging (with the same problem), to find out, I was missing the line:
setLayout(null);
It's so simple, so obvious.
Without this, the layout manager comes in, and messes up my properly placed components.
(Coordinated with magic numbers...)
Luckily, this time it only took five minutes to figure out, what's the problem.

I should make a T-shirt with this line, for the nights when creating a new project.
And for the mornings after the night before.