Continuation of >>62823481

continuation of Write a program in your language of choice that does the following:

- load an image (source image)
- get a list of all the colors in the source image
- create 2 blank images (image1 and image2)
- draw a random polygon or circle on image1 using a random color from source image
- compare image1 to the source image
- if it's closer in color to the source image than image2, copy image1 to image2; if not, copy image2 to image1 and continue drawing more random shapes and comparing
- post the results and bits of code

Other urls found in this thread:

pastebin.com/qRfz08Li
stackoverflow.com/questions/4196453/simple-and-fast-method-to-compare-images-for-similarity
github.com/matjojo/image-effects
stackoverflow.com/questions/2982711/c-image-processing-libraries
gitgud.io/sachiko/g-chan-random-lines
paste.pound-python.org/show/QKcSFlJFiihmM6QcMJ1G/
twitter.com/NSFWRedditImage

Sup Forums is not for homework, underage fag

kill yourself

Are you retarded? We've been playing around with this for a couple of days already

Fuck off back to Sup Forums.

proof of the pathetic state of this board
fucking mods need to start doing their job

>technology board
>thread about having some fun programming
>proof of the pathetic state of this board
What did he mean by this?

Don't feed him, he's fishing for (You)s out of desperation.
Someone run the program on a screenshot of his post.

Fuck off nodev.

What do you guys use for comparing the images?

How long before your assignment is due? I'm getting sick of these threads.

I've read about euclidean and manhattan distance but I'm too much of a brainlet to implement that.

I'm barely getitng it to draw a line right now, will worry about comparison when I get that far

why?
euclidean distance is simple
sqrt((x2 - x1)^2 + (y2 - y1)^2 + (z2 - z1)^2)
and manhattan distance is even simpler

abs(x2 - x1) + abs(y2 - y1) + abs(z2 - z1)

Here's my latest. It uses circles of decreasing size until a minimum, at which point it switches to lines.

I have a bunch of code that should do something but doesn't do anything, any suggestions on where I fucked up?
private void showButton_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
int Width = Image.FromFile(openFileDialog1.FileName).Width;
int Height = Image.FromFile(openFileDialog1.FileName).Height;
int x = 0;
int y = 0;
List srcColors = new List();
using (Bitmap srcPic = new Bitmap(openFileDialog1.FileName))
{
if (x < Width && y < Height == true)
{
Color srcColor = srcPic.GetPixel(x, y);
srcColors.Add(srcColor);
x++;
y++;
}
};
Bitmap Output = new Bitmap(Width, Height);
Random rnd = new Random();
for (int i = 0; i < iterationsController.Value; i++)
//iterationsController is a different control (one of those NumericUpDown controls)
{
int x0 = rnd.Next(0, Output.Width);
int y0 = rnd.Next(0, Output.Height);
int x1 = rnd.Next(0, Output.Width);
int y1 = rnd.Next(0, Output.Height);
int clr = rnd.Next(0, srcColors.Count);
Color rndColor = srcColors[clr];

Pen myPen;
myPen = new Pen(rndColor);
Graphics formGraphics = CreateGraphics();
formGraphics.DrawLine(myPen, x0, y0, x1, y1);
myPen.Dispose();
formGraphics.Dispose();
}
pictureBox1.Image = Output;
}
}

Turns out I implemented the manhattan one without knowing of its existence, kek.
Shouldn't have skipped math.

jesus christ
I was excited when the first of these posts appeared because I thought now new threads with challenges will start to pop up, but now you retards are just reopening the same thread again and again

It's because some of us completely suck and can't keep up, but hey you could make a new thread with another challenge.

Alternatively, when I finally get this working I'll definitely make a different thread. I'm very new to programming so it might take some hours tho

Exactly, anyone has any ideas for something new?

Then post new challenges, the 'do your own homework' fags will be around, but the fun people will be too

Maybe something with neural networks? An evolution simulator? Seen a few videos and those seem fun.

can confirm, I made a flappy bird clone in Lua and made a neural net that played it, was a lot of fun to do

Neural nets seem hard to get into, a lot of people on this board (including me) might struggle with that

yeah maybe I got ahead of myself, I thought that with all the tutorials in youtube getting into it shouldn't be too hard but thinking more about it it does seem awfully complicated

Conway's game of life is some what easy to implement if anyone wants an easier challenge.

> Having fun is not allowed

>- load an image (source image)
Constrain this requirement. There is shitload of difference between the file formats.

that's fair
>the 'do your own homework' fags will be around
not if op posts his own code/proof that he got it working

Nice. Repo where?

Now do it in the house and shapes like stars and decagons

Can someone please make one that's better than tux3/evolve

I need to vectorize images, my screens are high res.

show me an image with alpha in it too!

I tried creating random triangles and comparing the images root-mean square.

Use triforces

Left it running some more.

Very artistic.

My latest.
pastebin.com/qRfz08Li

Any chance you could get it working with non-isosceles triangles?

This looks nice, any chance of limiting the random positions to a grid?
Like randPos = randPos - (randPos % 32);?

I'm gonna give this a shot later tonight.

anyone got any ideas?

This sounds fun, I'll see if I can get it to work using JS.

Don't listen to the 'do your homework' faggots.

>new to programming
>using python
>made it to the part where I create another image and shape filled with random color from og pic
Not sure how to continue

Look into image comparison.

There's some good resources to be found here: stackoverflow.com/questions/4196453/simple-and-fast-method-to-compare-images-for-similarity , for example.

Sum of squared differences, treating per-pixel R, G, and B channels as separate differences.

Advantages include alpha channel being a trivial extension, and it's possible to weight different channels separately so you can have an image converge in the green before blue, for example.

I'm in a similar position but working with Visual C#, got code that should be drawing random shit but nothing is showing up

any ideas?

It works with any kind of random shapes.

I just this 1000 iters of triangles with random angle and shape but no size and it took 181 seconds. So unless anyone wants to share code I give up on them with Python.

Wait a fucking second. My CPU must have been fapping. Now 10000 iters in 205. Very strange.

Just check out previous thread

Meant for

no bad at all.

Late to the party. Using Java.

100M iterations, random lines between 3 and 20 pixels in length.

it is possible to do a second sub sampling within the line, so half of it matches more accurately, resulting in a better picture. I'll work on something when I get home from work, this project seems fun.

20k iterations took 323 seconds

20000 iters in my laptop in about 15 minutes, i3 on 1.6 ghz:

github.com/matjojo/image-effects

well, 900 seconds seems like t.CPU-let, and that was on a 400*400 image goddamn, what kinda CPU's you all running on?

Considering switcing to python at this point. The image library seems comfy, and I just can't find a solid image processing module for NodeJS.

Suppose it's as good a chance as ever to learn python ¯\_(ツ)_/¯

KEK

i know in python that

x**2 is slower ther x * x or generally in most languages square function is an expensive funciton.

4k iterations took with square computing 33 seconds

with x*x it took 9 seconds.

welp, I replaced my square with an x*x, thanks for that

P3

Hey I'm trying to do this using c++ but have no idea where to start can someone point me to an image library. Thanks

stackoverflow.com/questions/2982711/c-image-processing-libraries

I don't know any c++, just googled

I just checked. Spot on. Saves a lot on the Euclidean distance. Amazing that an interpreted language does not optimize this shit automatically.
Also implemented rectangles at an angle too.

those gifs are cool but please give some more time for the last frame to show?

Sorry I am cutting them short as I am not letting the full program to end while testing. I will refrain from posting unfinished ones.

>if it's closer in color to the source image than image2, copy image1 to image2; if not, copy image2 to image1 and continue drawing more random shapes and comparing

>tfw retarded and technically completed the task by comparing histograms

In hindsight, I don't know why I thought that would work lmao

Hacked something together quick in C++ and it takes about one and a half minutes to do one hundred million iterations with these random rectangles.

bump

Wtf is this real

>one and a half minutes to do one hundred million iterations

HOW

...

Holy shit, thanks man
I also tried with abs() and it seems to be even a bit faster (only a bit it's still better than nothing)

Any tips on an efficient line computation?

Mad this with c++, took me arround a day to Write the code. Takes a couple of minutes for 10M iterations.
Should be able to optimize a lot and use different shapes.

What image format are you guys using? I'm using .ppm because I wanted to use this to write a reader and writer for ppm

Bresenham's Line Algorithm
Xiaolin Wu's line algorithm

Thanks for the pic, I added it to my collection!

Looks like Terminator arm inspired artificial muscles.

...

10M iterations took about 70s using java

I'm new to programming and I am using python with PIL.
I'm getting only about 1 iteration for ever 3 seconds
what am I doing wrong?

pretty fucking good user

post your code

im giving up

You're probably testing the entire image when you should only be testing the pixels you drew on.

not him but hardstuck at comparison too

can you explain what should I actually look for
and why do we need img2

You don't "need" img2. I would wager the fastest implementations don't have img2. It's included in the original formulation of the problem to make it easier to understand it. img2 is the backup of the image before you added the object (circle, polygon etc) to img1. If the adding of the shape didn't make it more similar to the target image, we restore the backup from img2. If img1 is closer, we copy img1 to img2 in order to update the backup image.

How does the comparison work? Just loop through the entire image and over RGB and add the absolute value (or use any other more suitable norm) of the difference between the target image pixel value and the comparison image pixel value to an accumulator variable. If you compare two images, you'll get two accumulator variables, and the smallest of them represents the most similar image.

Now, if you want to make it faster, you'll need to restrict the area that you compare. Since you're adding an object to an existing image, you only need to compare that specific area, since the rest is the same on both images.

im going to test a slightly new approach to hopefully make the reuslting image more like a sketch
my idea is to limit the line length depending on the density of regional detail
currently doing canny edge detection and calculating and average over a small region and using threshholding to mark as a detailed region
i'd like to do something like the hevc segmenting where more bits are allocated to higher detail areas
will also look into adding constraints on line direction dependent on the direction of edges within a region

anyone have any ideas how to best get a measure of detail for a region?
first order derivative of each color space and threshhold according to amount of 0s?
second order derivate?

>You don't "need" img2
no
and you dont have to iterate throught the entire image either
you just have to compare the color of the line to be drawn with the appropriate space for the line on the source image
image processing libraries might have an implementation for line iteration (e.g. cv::LineIterator in OpenCV)
or use y=kx+m to do it with rounding conversion of the calculated coordinates

see my implementation if your interested
gitgud.io/sachiko/g-chan-random-lines
it performs reasonably well, it does 1m iterations in about 3 sec on a 6200u (compiled with -Ofast)

Dunno why its not doing anything, but shouldnt this
>(x < Width && y < Height == true)

work with
>(x < Width && y < Height)
alone. Also, when making new random, its better to have a seed, if the program runs through the new Random() too fast. By default the seed is based on the clock(changes every one second or something?), so if the function gets called too often, the numbers wont change. Better to call the function with some randomized seed, high precision counter(can't remember the name, but google will help) or something which changes with each clock cycle.

Just to add to that, not "randomized" seed or anything, but something which changes more often than the functions default-seed. Theres some different ways to do that, but not really sure which would be the best one. Just saying in case someone else runs to the same problem i ran into before. Had to make a randomized database, which ended up not being so random as the function got called too often.

>it does 1m iterations in about 3 sec
i should extend on this
the speed depends very much on the maximum length of the line, 3s is with the default of min(source.rows, source.cols) / 12
with length set to 10px it does 10m iterations in about 8s

...

Might be good to check if the iterationscontroller.Value is correct, might explain something if the for-loop doesnt do anything.

An excellent challenge thread with no sign whatsoever of the O(n) faggot. Maybe Sup Forums is not dead after all

I tried just putting an int there but it still did nothing

thanks for the tips, I'm still trying to get it to work but I think I might be doing some progress

10M iterations in 22s in scala

cute

Still 10M iterations, but using circles, took 644s

Damn... even at a length of 10pixel it takes 30 seconds to do 10m iterations...
How do you access all the Data that efficiently? I'm currently making a copy of the lines from the source image and the new image and then comparing them seperatly, but the copy process still takes up 50% of my compute time...

This loop crashes the program, what do
Bitmap srcPic = new Bitmap(openFileDialog1.FileName);
int x = 0;
int y = 0;
List srcColors = new List();
for (x = 0; x < srcPic.Width; x++)
{
for (y = 0; y < srcPic.Height; y++)
{
Color srcColor = srcPic.GetPixel(x, y);
if (srcColors.Contains(srcColor) != true)
{
srcColors.Add(srcColor);
}

}
y -= y;
}

Here's the code forgot to link it:
paste.pound-python.org/show/QKcSFlJFiihmM6QcMJ1G/

Not very pretty but basically it just compares the rectangle that gets replaced and not the whole image. It compares them in about the same way as what did.

I was thinking it could probably be made faster with AVX but what I wrote quickly which is dead simple and just does it one byte at a time seems pretty fast.