Bay 12 Games Forum

Please login or register.

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

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

kytuzian

  • Bay Watcher
    • View Profile
    • Kytuzian - Youtube
Re: Programming Help Thread (For Dummies)
« Reply #1350 on: March 05, 2015, 11:17:03 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.

Alright, I just assumed that having the negative brightness would be wrong, but even when I removed the max, I get identical images, that is:

Code: [Select]
MD5 (compare/im4.jpg-analyzed2.png) = e3fbe41f200789c6a1545973586aa230

MD5 (compare/im4.jpg-analyzed3.png) = e3fbe41f200789c6a1545973586aa230

Also, I know about the coordinates things, it's like that because it was quicker to write that way because of the way the image writing and stuff works. I changed it now.
« Last Edit: March 05, 2015, 11:20:15 am by kytuzian »
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1351 on: March 05, 2015, 11:37:45 am »

I'd like some of those processed images then please, including the source images to compare them with.
Logged

kytuzian

  • Bay Watcher
    • View Profile
    • Kytuzian - Youtube
Re: Programming Help Thread (For Dummies)
« Reply #1352 on: March 05, 2015, 12:01:02 pm »

I'd like some of those processed images then please, including the source images to compare them with.

Here:

https://www.dropbox.com/sh/e7v9fflysx8rncc/AACoZEPaWy7X51aVpSB6797wa?dl=0

im4.jpg is the original, and then im4-analyzed-noclamp is the one without the max(..., 0.0) and im4-analyzed-clamp is the one with it.

Also I probably should have mentioned this earlier, I'm using
Code: [Select]
img = imfilter_gaussian(img, [2, 2]) to do the blurring.
« Last Edit: March 05, 2015, 12:04:20 pm by kytuzian »
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1353 on: March 05, 2015, 12:03:21 pm »

Okay, of course you wouldn't see a difference, because negative color values are clamped to 0 either way when exporting them as images. Also you might notice that large positive color values are clamped to 1 from above, I suspect they would be much larger than 1. Maybe you would like to shift the images back into displayable intensities before visualizing them?
« Last Edit: March 05, 2015, 12:06:58 pm by MagmaMcFry »
Logged

kytuzian

  • Bay Watcher
    • View Profile
    • Kytuzian - Youtube
Re: Programming Help Thread (For Dummies)
« Reply #1354 on: March 05, 2015, 01:49:00 pm »

Okay, of course you wouldn't see a difference, because negative color values are clamped to 0 either way when exporting them as images. Also you might notice that large positive color values are clamped to 1 from above, I suspect they would be much larger than 1. Maybe you would like to shift the images back into displayable intensities before visualizing them?

Yeah that's rather stupid of me. I added the fixed version "im4-analyzed-fixed.png" to the folder, you should be able to see it. If that looks right then I'll see what I can do next.
« Last Edit: March 05, 2015, 01:56:17 pm by kytuzian »
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1355 on: March 05, 2015, 02:30:37 pm »

Yes, that looks way better.
Logged

Antsan

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1356 on: March 08, 2015, 07:20:25 am »

I'm trying to learn LaTeX so I can write a proper poslin specification. For this purpose I would like to define an "example" environment, which I can use to make code examples.
So this
Code: [Select]
\begin{example}
[ 1 2 + ]
> !
[ 3 ]
\end{example}
should be equivalent to this
Code: [Select]
\emph{Example}
\begin{lstlisting}
[ 1 2 + ]
> !
[ 3 ]
\end{lstlisting}

I tried to define it like this:
Code: [Select]
\newenvironment{example}{%
  \emph{Example}
  \begin{lstlisting}%
}{%
  \end{lstlisting}%
}
but that doesn't compile.
I tried to work around that via defining it as a command instead, but that doesn't work either. It seems using environments in definitions is not valid.
Any ideas or pointers?
Logged
Taste my Paci-Fist

highmax28

  • Bay Watcher
  • I think this is what they call a tantrum spiral...
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1357 on: March 11, 2015, 04:40:21 pm »

I'm currently trying to work with or and and statements in javascript for my class. Luckily, I'm given it in pseudocode so its easier to turn to javascript.

Unfortunately, shit happens like this where I have no idea why I'm getting a blank screen.

Code: [Select]
<html>
<head>
</head>
<body>
<script type="text/javascript">
// Program name: Upper Crust Admissions
// Purpose: Determine whether a student is admitted to a college
//   and whether the student gets a scholarship
// Author: Spencer Durette
// Date last modified: 11-Mar-2015

// Declare variables
var SATscore;            // student's total SAT score
var alumParent;          // whether a parent is an alum
var familyIncome; // total family income
var studentAdmitted;      // whether a student is admitted
var scholarshipGiven; // whether a scholarship is given

// Display program header, ask questions
document.write("Upper Crust College Admissions");
SATscore = prompt("What is the student's combined SAT score?","0");
SATscore = parseInt(SATscore);
alumParent = prompt("Is either parent an alumnus of the college (Y/N)?","N");
familyIncome = prompt("What is the family income?","0");
familyIncome = parseInt(familyIncome);

// Determine whether student is admitted to college, display result
if (SATscore >= 1400 || SATscore >= 1200 && alumParent == "Y" || SATscore >= 1200 && familyIncome >= 100000) {
studentAdmitted = "Y";
document.write("Congratulations! You have been admitted!");
}
else {
studentAdmitted = "N";
document.write("Sorry, you have not been admitted.");
}

// Determine whether student gets scholarship
if (studentAdmitted = "Y" && familyIncome < 100000) {
schoarshipGiven = "Y";
document.write "You have also been awarded a scholarship!";
}
else {
scholarshipGiven = "N";
document.write ("You are not being awarded a scholarship.");
}

// Thank the user and exit the program
document.write("Thanks for applying to Upper Crust!");
</script>
</body>
</html>

I'm still figuring this out, and unfortunately, this means I don't know whats wrong as javascript has no prompt as to what isn't working (or at least to my knowledge...)

Any thoughts on why I'm getting blanks?
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.

Arx

  • Bay Watcher
  • Iron within, iron without.
    • View Profile
    • Art!
Re: Programming Help Thread (For Dummies)
« Reply #1358 on: March 11, 2015, 05:26:45 pm »

It looks to me like you're expecting it to work like "this or thisandthis or thisandthis" where thisandthis is one condition, but what you're getting is "this, this, or this, and this and this". Currently only someone with a SAT of 1200 or more, an alumnus parent, and an income of over 10000 satisfies the requirements.

Does that make sense at all? As a semantic error, it wouldn't give you any messages.
Logged

I am on Discord as Arx#2415.
Hail to the mind of man! / Fire in the sky
I've been waiting for you / On this day we die.

highmax28

  • Bay Watcher
  • I think this is what they call a tantrum spiral...
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1359 on: March 11, 2015, 05:41:48 pm »

It looks to me like you're expecting it to work like "this or thisandthis or thisandthis" where thisandthis is one condition, but what you're getting is "this, this, or this, and this and this". Currently only someone with a SAT of 1200 or more, an alumnus parent, and an income of over 10000 satisfies the requirements.

Does that make sense at all? As a semantic error, it wouldn't give you any messages.
I just noticed that. Whoops. I'm gonna fix that... Aaaaaand... I'm still getting a blank screen. Same deal with another one I'm doing, so it may just be the declaring of the or and and statements. Or my if statements...

That or clearly I'm the dummy this thread is talking about :P

Code: [Select]
<html>
<head>
</head>
<body>
<script type="text/javascript">
// Program name: Grade Reporter
// Purpose: Determines student's grade,
//   based on percentage and attendance
// Author: Spencer Durette
// Date last modified: 11-Mar-2015

// Declare variables
var percentage     // student's percentage for classwork
var absences        // number of absences during term
var letterGrade         // assigned letter grade
var failedForAbs   // whether student failed for absences

// Display program header, ask questions
document.write("Welcome to the Grade Reporter!")
percentage = prompt("What is your percentage for classwork? (enter 50% as 50)","0")
percentage = parseInt(percentage)
absences = prompt("How many times were you absent this term?","0")
absences = parseInt(absences)

// Determine whether student fails or gets 3 added percentage points based on attendance
if absences > 5 {
failedForAbs = true
document.write("You have failed for having more than 5 absences.")
}
else if absences <= 2 {
percentage = percentage + 3
document.write("Your percentage has been increased by 3% for having 2 or fewer absences.")
}

// Determine letter grade
if percentage < 60 Or failedForAbs == true {
letterGrade = "F"
}
else if failedForAbs != true {
if percentage < 70 {
letterGrade = "D"
}
else if percentage < 80 {
letterGrade = "C"
}
else if percentage < 90 {
letterGrade = "B"
}
else {
letterGrade = "A"
}
}

   // Display letter grade and thank the user
   document.write("Your letter grade is " + letterGrade)
   document.write("Thanks for using the Grade Reporter!")


This is my other one that has the same problem. Once again, not my pseudocode (however, the one thing that I did after with my own pseudocode works like a charm... Go figure)
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.

kytuzian

  • Bay Watcher
    • View Profile
    • Kytuzian - Youtube
Re: Programming Help Thread (For Dummies)
« Reply #1360 on: March 13, 2015, 07:30:37 pm »

Yes, that looks way better.

Alright so I did the image subtraction, then used the same method from before to extract significant regions from the subtraction of the images. It does work better (and faster) now, so thank you.

I'd still like to improve it more, however, as it gives, on average, about 20 significant regions, as opposed to probably over 40 from before. If you (or anyone else, of course) have any more suggestions I'd love to hear them.

Thanks

-code-

This is my other one that has the same problem. Once again, not my pseudocode (however, the one thing that I did after with my own pseudocode works like a charm... Go figure)

It seems to me that you should have parentheses around your conditions for your if statements. Not having much experience with Javascript, I went to Chrome's console and it yells at me if I don't have them, so I would assume that is also a problem for you.
« Last Edit: March 13, 2015, 07:34:43 pm by kytuzian »
Logged

Antsan

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1361 on: March 15, 2015, 05:49:58 am »

-snip-
Seems the way to do this is via `\lstnewenvironment' from he listings package.
Logged
Taste my Paci-Fist

Reelya

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1362 on: March 15, 2015, 06:11:32 am »

ctrl-shift-j brings up the browser error log, this has things you can click on to highlight the line that caused the crash, e.g. :-

Quote
if percentage < 70

You don't have brackets around your conditionals. These are 100% required. For each if statement it needs all the conditions between a pair of () brackets. These brackets must match, and tell the program what things belong to that if statement.

You can't do if (x==1) || (x==2) either, since only the first set of brackets will be understood as belonging to the if statement. You could do one of these instead:

if ( (x==1) || (x==2) )

or just

if ( x==1 || x==2 )

You can also nest conditions to indicate how the logic works:

if ( (percentage > 70 && class=top )  ||  iamrich = true)
   grade = highdistinction;

^ this would give the "highdistinction" grade if the person got over 70 and was in the top class, OR if they were rich, regardless of grades. if the brackets went the other way:

if ( percentage > 70 && (class=top  ||  iamrich = true) )
   grade = highdistinction;

This would give the highdistinction to anyone who got over 70%, but only if they were either in the top class OR rich. I hope this example gives you an insight into how to code your thought process into the if statements. When you have any doubt about the order of operations, throw brackets around the individual conditonals. The only time you will 100% certain you don't need them is when all connectors are either AND or OR, since it won't matter then what order they are evaluated.

I'd also caution always using c-style semi-colons at the end of lines that need them. If you get into the habit of leaving them off, this will fuck you over when you try and learn other c-style languages. Very few are as forgiving as JavaScript.
« Last Edit: March 15, 2015, 06:55:42 am by Reelya »
Logged

Biag

  • Bay Watcher
  • Huzzah!
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1363 on: March 15, 2015, 09:51:25 pm »

I'd also caution always using c-style semi-colons at the end of lines that need them. If you get into the habit of leaving them off, this will fuck you over when you try and learn other c-style languages. Very few are as forgiving as JavaScript.

+1 to this. Javascript will attempt to insert any missing semicolons for you, which can cause strange bugs that are super hard to figure out.
Logged

MaximumZero

  • Bay Watcher
  • Stare into the abyss.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1364 on: March 20, 2015, 08:22:15 pm »

Ladies and gentlemen, I've decided to spend a lot more time away from Bay12, and as such am no longer moderating many threads that I've created. Because of this, I'm locking most of them.

There's another programming thread here: http://www.bay12forums.com/smf/index.php?topic=98412.0

I'm sorry if this causes any inconvenience.
Logged
  
Holy crap, why did I not start watching One Punch Man earlier? This is the best thing.
probably figured an autobiography wouldn't be interesting
Pages: 1 ... 89 90 [91]