Computed Tomography: Matlab to C/OpenCV code conversion error - c

I am working on a Computed Tomography problem, in which I have to simulate the generation of the raw data or sinogram that a CT apparatus generates.
Matlab has an in-built function "radon()" to simulate the same. I have successfully written a custom code in Matlab to generate the sinogram (ie: without using radon() ).
I have converted this code into C, using the OpenCV library to handle the loading/display/saving of images.
The problem is that though my matlab output generates the sinogram as expected, my C code does not. I have merely translated the Matlab code into C but the C output is oriented differently as well has black strips in between. The gray levels in the C output kind of resemble the Sinogram gray levels and pattern generated by the matlab code. Only thing it appears segmented in C.(I will send the images across if you gimme your mail id since i cannot attach them here.)
Could someone help me out as to why this is happening? I have peer-reviewed my code and checked for type cast errors, memory allocations etc. But They all seem correct.
Does matlab handle data that differently than C? What could be the explanation for the tilt?
Please Help me out. Do let me know if you need any more clarification regarding the problem statement or need to see the algorithm.
Thanks!

Very hard to help with a question like this, when we don't see either code, the output, or the expected output.
Perhaps you can upload the images to some public image hosting, and add links from the question?
If you're doing trigonometric function calls (sin() and friends), I would pay extra attention to the arguments used, and also check if maybe Matlab is delivering more precision in the result, somehow. Of course, this is a stab in the dark since I'm not familiar with your domain.

Here are the images related to the doubt I asked in the original post
The expected output:
http://www.photoshop.com/users/pyridot/albums/a40e3f7326d942ff821fc00612e6b458/view#e027c2b94bfd4210870bc6c57b1f1a03
The C Output:
http://www.photoshop.com/users/pyridot/albums/a40e3f7326d942ff821fc00612e6b458/view#ff529abedb3e49aa8865276f2c2bc625

Related

C logging framework compile time optimization

For a certain time now, I'm looking to build a logging framework in C (not C++!), but for small microcontrollers or devices with a small footprint of some sort. For this, I've had the idea of hashing the strings that are being logged to a certain value and just saving the hashed value with the timestamp instead of the complete ASCII string. The hash can then be correlated with a 'database' file that would be generated from an external process that parses the strings out of the C source files and saves the logged strings along with the hash value.
After doing a little bit of research, this idea is not new, but I do not find an implementation of this idea in C. In other languages, this idea has been worked out, but that is not the goal of my exercise. An example may be this talk where the same concept has been worked out in C++: youtube.com/watch?v=Dt0vx-7e_B0
Some of the requirements that I've set myself for this library are the following:
as portable C code as possible
COMPILE TIME optimization/hashing for the string hash conversion, it should be equivalent to just printf("%d\n", hashed_value) for a single log statement. (Assuming no parameters/arguments for this particular logging statement).
arguments can be passed to the logging statement similar to the printf function.
user can define their own output function (being console, file descriptor, sending the data directly over an UART connection,...)
fast to run!! fast to compile is nice to have, but it should not be terribly slow.
very easy to use, no very complicated API to use the library.
But to achieve this in C, what is a good approach? I've tried several things now, but do not seem to have found a good method of achieving this.
An overview of things I've tried so far, along with the drawbacks are:
Full pre-processor string hashing: did get it working, but the compile time is terribly slow. Also, this code does not feel to be very portable over multiple C compilers.
Semi pre-processor string hashing: The idea was to generate a hash for each string and make an external header file with the defines in of each string with their hash value. The problem here is that I cannot figure out a way of converting the string to the correct define preprocessor value.
Letting go of the default logging macro with a string pointer: Instead of working with the most used method of LOG_DEBUG("Some logging statement"), converting it with an external parser to /*LOG_DEBUG("Some logging statement") */ LOG_RAW(45). This solves the problem of hashing the string since the hash will be replaced by the external parser with the correct hash, but is not the cleanest to read since the original statement will be a comment.
Also expanding this idea to take care of arguments proved to be tricky. How to take care of multiple types of variables as efficiently as possible?
I've tried some other methods but all without success. Especially when I want to add arguments to log the value of a variable, for example, it gets very complicated, and I do not get the required result...

wmv2 # 0xb42400 warning, clipping 1 dct coefficients to -255..255

[wmv2 # 0xb42400]
warning, clipping 1 dct coefficients to -255..255
I'm modifying some code in a C API that interacts between FFmpeg and and an AS3 Air application to encode a video after creating something.
WMV was working okay earlier but now I've set things back I'm getting this very peculiar warning coming from the c library but it doesn't make any sense and googles not providing many answers.
I was wondering if anyone out there knew what this warning was about? When the file comes back to me it's totally empty with 0 frames. I must have changed something so I'm comparing the file from a few days ago with this one looking for anything that may have caused it to no longer work. But I was wondering if anyone had any better ideas than blindly looking through old and new code.
This particular warning comes from the FFmpeg core code. It is just warning that it had to perform an adjustment on some bits of the video stream in order to successfully decode it. It might help to understand that the WMV2 algorithm (being decoded, per your error message) was reverse engineered from binary code and reimplemented in FFmpeg, which is why things like this slip through the cracks.

How Debuggers Find Expressions From Code Lines

A debugger gets a line number of an expression and translates it into an program address, what does the implementation look like? I want to implement this in a program I'm writing and the most promising library I've found to accomplish this is libbfd. All I would need is the address of the expression, and I can wait for it with ptrace(2). I can imagine that the debugger looks for the function name from the C file within the executable, but after that I'm lost.
Does anyone know? I don't need a code example, just enough info so that I can get an idea.
And I don't mind architecture-specific answers, the only ones I really care about are Arm and x86-64.
You should take a look at the DWARF2 format to try to understand how the mapping is done. Do consider how DWARF2 is vast and complex. It's not for everyone, but reading about it might satisfy your curiosity faster and more easily than reading the source for GCC/GDB.

Save image in C

I'm just learning C language, so I apologize in advanced if my question is not clear or if I'm asking the wrong question (or a dummy question).
I wrote a code in C that produces the fractal fern points and then plots them using openGL.
My code is similar to the one found here (http://www.cs.csubak.edu/~marc/code/opengl/fern.c).
Now I want to save the image that I obtained to a file. I've been searching about this and most of the answers suggest to use a library for this, but I'd like to write my own function. I understand that the first step is to use glreadpixels to read the pixel, but I'm not sure what should be the next step.
Thanks for your time and help
libbmp is a very good choice.
http://code.google.com/p/libbmp/

How to evaluate if a code is correct against a submitted solution

I´m searching information about how to compare two codes and decide if the code submitted by someone is correct or not (based on a solution code defined before).
I could compare the output but many codes may have the same output. Then I think I must compare someway the codes and give a percentage of similitude.
Anybody can help me?
(the language code is C but I think this isn´t important)
Some of my teachers used online automated program grading systems like http://web-cat.org/
In the assignment they would specify a public api you must provide, and then they would just write tests against your functions, much like unit tests. They would intentionally pick tests that would exploit boundary conditions and other things students are notorious for not thinking about, and just call your code with many different inputs to try to get your code to fail.
Sometimes they would hardcode the expected values, other times they would allow values within a range, and other times they just did the assignment themselves and made it so your own code has to match the results produced by their code.
Obviously, not all programs can be effectively graded this way. It's also kinda error prone in that sometimes even the teacher made a mistake and overflowed an int or something, then the correct student submissions wouldn't match the teachers incorrect results. But, a system doesn't need to be perfect to be useful. But I think this raises an important point in that manually grading by reading the code won't necessarily reveal all mistakes either.
Another possibility is copy the submitted code, strip out all of the white space and search for substrings that must exist for the code to be correct and/or substrings that cannot exist for the code to be considered correct. The troublesome bit might be setting up to allow for some of the more tricky requirements such as [(a or c),((a or b) and c),((a or b) and c)], where the variables are the result of a boolean check as to if the substring related to the variable exists within the code.
For example, [("printf"),("for"), (not "1,2,3,4,5,6,7,9,10")], would require that "printf" and "for" be substrings in the code, while "1,2,3,4,5,6,7,9,10" i I'm not familiar with C, so I'm I'm assuming here that "printf" is required to be able to print anything without involving output streams, which could be accounted for by something like [("printf" or "out"),("for"), (not "1,2,3,4,5,6,7,9,10")], where "out" is part of C code required to make use of output streams.
It might be possible to automatically find required substrings based on a "correct" code, but as others have mentioned, there are alternative ways to do things. Which is why hard-coding the "solution" is probably required. Even so, it's quite possible that you'll miss a required substring, and it'll be marked as wrong, but it's probably the only way you can do what you ask with some degree of success.
Regular expressions might be useful here.

Resources