Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 88 89 [90] 91

Author Topic: Programming Help Thread (For Dummies)  (Read 100395 times)

Reelya

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1335 on: February 24, 2015, 04:25:10 pm »

the loop looks fine. Something else is failing.

Debug statements can help, that is, output the current loop counter or simple "hello" type messages each loop. or, add the count into the text of the prompt. Maybe every second prompt is being auto-closed or some weirdness.

one thing clearly wrong is declaring "average = total/5". At that point in the program, the previous statement was "total=0". execution flows down the page, so average will be set to 0/5 = 0 and never get fixed.

you need to just set "var average" at the start, and put "average = total/5" AFTER total is calculated but just before you display the data.

think of programming like following a recipe. the steps happen in the order they appear on the page. you calculating the average at the start is like putting "pour the cake mix into the mould" before you've done the "add eggs, sugar, flour, salt and milk" steps.
« Last Edit: February 24, 2015, 04:31:36 pm by Reelya »
Logged

highmax28

  • Bay Watcher
  • I think this is what they call a tantrum spiral...
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1336 on: February 24, 2015, 05:45:17 pm »

Thanks Reelya. I gave it a shot and it repeated the same problem. I also just found out it has to do with the lowest value thing. For some odd reason, when I give it a number that's bigger, its fine, but when its less then the lowest, it shuts down. Ascending, it can run all the way up (I did 12, 13, 14, 15, 16 and it worked perfectly but the lowest value was 0...)
Logged
just shot him with a balistic arrow, i think he will get stuned from that >.>

"Guardian" and Sigfriend Of Necrothreat
Jee wilikers, I think Highmax is near invulnerable, must have been dunked in the river styx like achilles was.
Just make sure he wears a boot.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1337 on: February 24, 2015, 06:27:49 pm »

That's because you wrote "lower" instead of "lowest". Also you might want to consider initializing "lowest" to a really high value and "highest" to a really low one instead of checking for zeroness, because that can misfire when you actually input 0.
Logged

highmax28

  • Bay Watcher
  • I think this is what they call a tantrum spiral...
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1338 on: February 24, 2015, 07:35:59 pm »

That's because you wrote "lower" instead of "lowest". Also you might want to consider initializing "lowest" to a really high value and "highest" to a really low one instead of checking for zeroness, because that can misfire when you actually input 0.
Whats absolute zero in Celsius? :P I'll set it to that, since the default for all values is room temperature. It works now, so I can't thank you guys enough!
Logged
just shot him with a balistic arrow, i think he will get stuned from that >.>

"Guardian" and Sigfriend Of Necrothreat
Jee wilikers, I think Highmax is near invulnerable, must have been dunked in the river styx like achilles was.
Just make sure he wears a boot.

Reelya

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1339 on: February 25, 2015, 03:12:51 am »

That's because you wrote "lower" instead of "lowest". Also you might want to consider initializing "lowest" to a really high value and "highest" to a really low one instead of checking for zeroness, because that can misfire when you actually input 0.
Yeah I missed that before, just caught it now myself. "lower" isn't declared. I hate typeless languages. Sure, they're faster to code for, but it's like saying a car with no brakes goes faster...it's all good until you need to stop at the lights.

if you were using a typed language the compiler would have already told you there was an error with the name and refused to run the thing in the first place. Screw JS and it's "everythings ok i'll run the script now ... no wait it's broken so I'll just crash without saying anything" attitude.
« Last Edit: February 25, 2015, 03:15:04 am by Reelya »
Logged

monkey

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1340 on: February 25, 2015, 09:50:12 am »

There should be a warning/error in the console (f12 to open in firefox/chrome, I think)
Logged

Gentlefish

  • Bay Watcher
  • [PREFSTRING: balloon-like qualities]
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1341 on: February 25, 2015, 11:57:22 am »

Another neat thing you can do is assign any max/min variables to the first number in whatever you're searching. then it's only comparing through itself and not some outside number.

kytuzian

  • Bay Watcher
    • View Profile
    • Kytuzian - Youtube
Re: Programming Help Thread (For Dummies)
« Reply #1342 on: March 04, 2015, 09:11:46 am »

I'm not exactly sure if this question really fits here, because it's kind of long and not really in the same vain as a lot of other questions.

Here is the code file (it's 785 lines long so I figure it's best to not post it here). It isn't really important for my problem though, because my question is is more algorithmic in nature.
https://drive.google.com/file/d/0BzgXJ3LjGyQzWmJ4ZzRyNGlmZ2M/view?usp=sharing

I'm running it through the

Code: [Select]
get_significant_objects_in_files(directories::Array{ASCIIString, 1}, old_name::ASCIIString, new_name::ASCIIString,
    brightness_range::TestRange, area_range::TestRange, verbosity::Int64, new_graph_tolerance::Float64,
    color::SimpleColor = black, tolerance = 1.0,
    pos::Point = Point(0,0), d = 10^6)

function if you're curious.

So the objective is to find the supernovae in images such as these:

Spoiler (click to show/hide)

My current approach is pretty simple.

  • Get a list of all significant areas of non-background color in the two image.
  • Filter out those regions which contain are too dark to be the supernova or have too few or too many pixels.
  • Find all regions which have a significant intersection (greater than 80% or so of total area) and remove those from the list of candidates.
  • All the remaining regions are possible candidates for the supernova.

However, this approach has produced far too many possible candidates (as few as twenty, as many as 120 out of a total of roughly 1500 regions per image set). The target (in the center) is usually in the list of regions, so that's not a problem, it's just that too many are there to reasonably sift through.

So essentially, I'm looking for ways to improve or even entirely change my algorithm.

Thanks!
« Last Edit: March 04, 2015, 09:15:40 am by kytuzian »
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1343 on: March 04, 2015, 10:20:16 am »

My approach would be to Gaussian blur both images by, say, 16 pixels, then align the color distribution curves, then subtract one image from the other and find some extreme values.
Logged

kytuzian

  • Bay Watcher
    • View Profile
    • Kytuzian - Youtube
Re: Programming Help Thread (For Dummies)
« Reply #1344 on: March 04, 2015, 11:56:15 am »

My approach would be to Gaussian blur both images by, say, 16 pixels, then align the color distribution curves, then subtract one image from the other and find some extreme values.

Alright I'm not exactly an expert on this sort of stuff, so can you please explain it in more explicit terms?

The Gaussian blur I'm fine with. So for color distribution curves, do you mean like a color histogram kind of thing? And what do you mean by subtracting colors from each other, simply getting the intensity of a pixel in the first imagine and subtracting the corresponding pixel intensity from the other image? And I believe I can handle finding the extremes once I understand everything else.

Sorry I don't know image processing and whatnot very well.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1345 on: March 04, 2015, 01:56:47 pm »

Exactly. A simple way to align the color distribution is to find the mean brightness and standard deviation of each image and normalize it using those values: pixel -> (pixel - mean)/stdev. The gaussian blur at the beginning is there so your standard deviation is less affected by noise. And yes, image subtraction is pixelwise.
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1346 on: March 04, 2015, 02:05:48 pm »

Maybe a neural network approach is better for that sort of thing than trying to hand-create an algorithm. Split up each image into many overlapping small regions (I'd overlap per pixel), train the NN on the sub-images to correctly output is supernova /is not.

Things are going to be easier - since it's just outputting a binary decision, there's only one NN node in the output layer, so you can invest in more mid-layer neurons.

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1347 on: March 04, 2015, 07:42:58 pm »

PTW for any future questions I may have.
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

kytuzian

  • Bay Watcher
    • View Profile
    • Kytuzian - Youtube
Re: Programming Help Thread (For Dummies)
« Reply #1348 on: March 05, 2015, 10:44:44 am »

    Exactly. A simple way to align the color distribution is to find the mean brightness and standard deviation of each image and normalize it using those values: pixel -> (pixel - mean)/stdev. The gaussian blur at the beginning is there so your standard deviation is less affected by noise. And yes, image subtraction is pixelwise.

    I implemented the first part of this, that is:

    • Gaussian blur the image.
    • Do the pixel_val = (pixel_val - mean_val)/stdev thing.
    • Subtract the two images from each other.

    By the way, I calculated the new pixel values with [/list]
    Code: [Select]
    new_img[y,x] = max(Gray{Float64}((float64(img[x,y].val) - mean_brightness) / stdev_brightness), 0.0)
    However, the final image (the subtracted one), doesn't really seem to be valuable for processing in the way I want. They generally don't have the desired region in the center of the image, and the other regions have "holes" in them. The two images (the original, and the new), after processing, although sometimes the procedure helps, sometimes also form "blobs". It's difficult to describe, I can provide pictures later.

    Maybe a neural network approach is better for that sort of thing than trying to hand-create an algorithm. Split up each image into many overlapping small regions (I'd overlap per pixel), train the NN on the sub-images to correctly output is supernova /is not.

    Things are going to be easier - since it's just outputting a binary decision, there's only one NN node in the output layer, so you can invest in more mid-layer neurons.

    Yeah that's also a possibility. I'll probably end up implementing this one as well for comparison.

    MagmaMcFry

    • Bay Watcher
    • [EXISTS]
      • View Profile
    Re: Programming Help Thread (For Dummies)
    « Reply #1349 on: March 05, 2015, 10:52:53 am »

    Code: [Select]
    new_img[y,x] = max(Gray{Float64}((float64(img[x,y].val) - mean_brightness) / stdev_brightness), 0.0)
    Okay, first of all, after subtracting the mean brightness from the image, over half of the image will have negative brightness. That's okay, and under no circumstances should you then go on to clamp the resulting values to be positive, because you'll lose so much information. Technically, since you'll only be looking at minima and maxima, you don't even have to subtract the mean_brightness and get the same extreme points, but I added that for completeness.
    Second, you switched the coordinates around, so your image is mirrored along the main diagonal and the supernovae might be in different locations than you expect.
    Logged
    Pages: 1 ... 88 89 [90] 91