World: r4wp
[#Red] Red language group
older newer | first last |
Bo 27-Jun-2013 [8899x2] | Could it be a problem that I'm type casting im1 to an integer in the line im: 0 ?? |
Forget it, that can't be the problem. | |
Kaj 27-Jun-2013 [8901] | That's not a cast, just an assignment |
Bo 27-Jun-2013 [8902] | I thought maybe the type was cast by the value you assigned to it. |
Kaj 27-Jun-2013 [8903] | Declared, but not cast, because it wasn't known yet |
Bo 27-Jun-2013 [8904] | The problem I'm trying to solve is to convert two seperate images to grayscale and then compare the pixels in each image to each other to look for big variations in contrast between the pixels. |
Kaj 27-Jun-2013 [8905] | You did upgrade your Red/System, didn't you? |
Bo 27-Jun-2013 [8906x2] | If I can't assign the answer of a calculation to a word and then use that word in other calculations, then it's a roadblock that I'm not sure how to overcome. |
Yes, I updated Red/System yesterday from Github. | |
Kaj 27-Jun-2013 [8908x2] | I found many such bugs in the past, so I would like to think they're gone, but it looks like you found another :-) |
Doc doesn't do many byte manipulations, so it's up to us to test them | |
Bo 27-Jun-2013 [8910] | OK. Curecode doesn't work for me for some reason, so how do I submit this bug? |
Kaj 27-Jun-2013 [8911] | Red is not in Curecode. The tracker is on GitHub |
Bo 27-Jun-2013 [8912] | OK. I'll enter it there. |
PeterWood 27-Jun-2013 [8913x3] | The calculation is okay. Code: Red/System [] red: as byte! 240 green: as byte! 120 blue: as byte! 60 greyscale: ((as integer! red) / 3) + (as integer! green) + (as integer! blue) print [greyscale lf] OUTPUT: -= Red/System Compiler =- Compiling /Users/peter/VMShare/Code/Red-System/test.reds ... Script: "Red/System IA-32 code emitter" (none) Script: "Red/System Mach-O format emitter" (none) ...compilation time: 122 ms ...linking time: 10 ms ...output file size: 16384 bytes ...output file name: builds/test 260 |
It may be an issue with the dereferencing. Could you try by assigning img1/r etc to temporary variables. | |
Oops, here's the proper code and correct answer: Red/System [] red: as byte! 240 green: as byte! 120 blue: as byte! 60 greyscale: ((as integer! red) / 3) + ((as integer! green) / 3) + ((as integer! blue) / 3) print [greyscale lf] OUTPUT ...compilation time: 133 ms ...linking time: 13 ms ...output file size: 16384 bytes ...output file name: builds/test 140 | |
Kaj 27-Jun-2013 [8916x2] | Your immediate problem should be solved if you do |
im1: as-byte 0 | |
Bo 27-Jun-2013 [8918x3] | Well, that seems to have worked around the problem! Thanks guys! |
Now I can work on making some real progress! :-) | |
I'm amazed by how fast Red/System is. | |
PeterWood 27-Jun-2013 [8921] | Excellent ! |
Kaj 27-Jun-2013 [8922] | Your code could be optimised a bit :-) |
james_nak 27-Jun-2013 [8923] | Kaj, I think there was something to the jarsigner being commented out in the file. I'll have to wait for Doc and Pekr to chime in. |
Kaj 27-Jun-2013 [8924] | Yes |
Bo 27-Jun-2013 [8925] | I'd love to learn how to optimize my code! |
Kaj 27-Jun-2013 [8926] | Are you low on memory? |
PeterWood 27-Jun-2013 [8927] | A simple one: im1: (as integer! r + g + b) / 3 |
Kaj 27-Jun-2013 [8928] | That won't work |
PeterWood 27-Jun-2013 [8929x2] | I meant : im1: (as integer! r) + (as integer! g) + (as integer! b) / 3 |
2 additions & 1 division against 3 divisions & 2 additions | |
Kaj 27-Jun-2013 [8931x2] | im1: (as-integer img1/r) + img1/g + img1/b / 3 |
But yes, that was my general idea | |
PeterWood 27-Jun-2013 [8933] | :-) |
Bo 27-Jun-2013 [8934] | I now have a working rudimentary motion detection algorithm. Now it's time to tune it with my special formula. |
Kaj 27-Jun-2013 [8935] | If you're not memory constrained, you can leave the / 3 out completely and compare two grayscales as integer values |
PeterWood 27-Jun-2013 [8936x3] | Im1 is already an integer in Bo's code. |
if you're desparate for a few millisecs, reversing the loop to start at the end and work toward the front will help. | |
(Subtraction being marginally faster then addiiton). | |
Kaj 27-Jun-2013 [8939] | That could be cast to byte again, to save the grayscale, but yes, there's no need to divide by 3 if it's just for the comparison |
Bo 27-Jun-2013 [8940] | I'm passing the processed image back out to Rebol to convert back into an image for visual verification of the motion detection algorithm. That part works fine. :-) |
Kaj 27-Jun-2013 [8941x3] | Subtraction faster than addition? That would surprise me. It's comparison to 0 that may be faster |
Further, the bumping of r, g and b each iteration is relatively much work, because you're also having to use them as indexes. It's more efficient to make a byte pointer for each and advance those | |
But it's probably even faster to iterate through the image with one integer pointer, because the pixels happen to be four bytes, and then use indexes of 2, 3 and 4 for r, g and b | |
Bo 27-Jun-2013 [8944] | So are you saying that if 'img1 is a pointer, to do the following? img1r: img1 + 2 img1g: img1 + 3 img1b: img1 + 4 and then img1r: img1r + 4 img1g: img1g + 4 img1b: img1b + 4 would be faster than what I'm doing now? |
PeterWood 27-Jun-2013 [8945] | You're correct. I checked and the optimisation benefit through "loop inversion" apparently comes from reducing the number of jumps in the underlying code not difference in speed in atrithmetic. |
Bo 27-Jun-2013 [8946] | OK, so this would be even faster: r: 2 g: 3 b: 4 until [ ...do stuff here... img1: img1 + 4 ...comparison... ] |
Kaj 27-Jun-2013 [8947] | Bo, yes, that would be more efficient, because you can then index with 1 |
Maxim 27-Jun-2013 [8948] | Bo, that's basically how it'd be done in C |
older newer | first last |