I am in need of C version(not C++) of imagesc function in MATLAB. I am in conversion of a MATLAB program to C(It is the requirement). The only thing left to implement is imagesc functionality. I don't necessarily need to plot or show the image in a window. I can write the image to a bitmap file also. So in essence, I need a matrix of RGB color values or grayscale color values as the result of this implementation.
So, I am looking for a simple library that is portable to Windows and Linux, and also dothe above. Or, I am ready to implement one of my own. But, I don't have a clue on how to do that. If there is no such library, would you please provide some information on implementing it?
Man, did you do a single Google search? There's tons of image manipulation libraries for C. ImageMagick's C library is one decent example, but if you don't like it you have many options.
Look at OpenCV, a computer vision and image processing library that works with C and C++. To accomplish something similar to imagesc in C++, I use the functions imread and imshow or alternatively I load the data in a Mat structure and I display it with imshow.
Related
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
I want to display an image using c in linux platform.And now i have read the image file ( gif)into an array of char. But I don't know what to do next to display it? Can anybody help me?
This is a quite complicated question since you're not being very specific.
C in itself doesn't have a concept of an "image" or even a "display". You need to mix in some environment-specific details that add such concepts, for instance you could work with the Framebuffer in (console) Linux, the X11 window environment, GNOME/GTK+, KDE or perhaps Enlightenment.
All of these give radically different answers.
You need a graphic toolkit to do that. Plain old C language is not enough.
You can try these toolkits:
QT
GTK
There are many others that will also do what you want, but these two are among the most populars I guess.
Does anyone know of a good steganography library I can use thats written in C or Objective-C? It would need to be used in a Mac OS X application.
My provocative answer will be that you should try to implement/learn some algorithms for image hiding/unhiding yourself. Sample algorithm of 3-bit image hiding into 24-bit image is very simple and consists of about 10 Python lines or so (of course it may be a bit more with C/Obj-C). And you will get not bad quality of stego image - about 87.5% of original quality. So check my blog article about this steganography method.
This stego decoding method is done in GPU pixel shader program for fast decoding procedure.
However encoding was done with Python script which after use was deleted ;P
But i think that encoding procedure is very straightforward and can be understood from my blog article. If any questions about my stego algorithm- feel free to ask.
I am wondering how I can both import and export bitmaps to and from C. I'm basically lost on where to begin.
A bitmap in memory looks similar to this:
struct Image {
int width;
int height;
char *data; // 1 byte per channel & only 1 channel == grayscale
}
struct Image theImage;
theImage.width = 100;
theImage.height = 100;
theImage.data = malloc(sizeof(char) * theImage.width * theImage.height);
As to importing and exporting, there are some really simple file formats out there, take a look at BMP. For more complex formats you best use an already available library.
Most frameworks already have load/save methods for the most common fileformats. You could take a look at SDL if you're looking for a lightweight library.
Have you taken a look at ImageMagick's C API wrapper, MagickWand? Here's the documentation if you want to peruse.
I like using SDL with the dummy driver. You can draw onto an in-memory buffer just like you would onto a screen, then save it out to a PNG or whatever with SDL_image or similar.
Another popular library for this is GD.
The simple answer is to use an appropriate library. What library is appropriate will depend on what platform you are using. On a GUI platform the GUI API/Framework will include these facilities.
I like the netpbm/pbmplus tools, although I usually like the command line; the API is efficient but not much fun to use.
This semester I wrote a significant amount of software for beginning students to use to manipulate images; you might want to check out the homework assignments and supporting software for the Tufts course Machine Structure and Assembly-Language Programming.
The term "bitmap" is somewhat generic, unless you specifically mean a Windows BMP.
I'd recommend using an image processing library on your platform (like gd). A good graphics library has routines to do input and output with images in various formats.
FreeImage is excellent. I've used this for my own game development work, and it supports tons of formats. Here's the list of features and formats supported - http://freeimage.sourceforge.net/features.html
Does anybody know a good C sample that loads bitmaps and handles all the cases: rle, b/w bitmaps, so on?
Code should be cross-platform.
Thanks.
I would suggest using a library like SDL image
If you are looking for a minimal bmp loader this link will give you all you need to know about the BMP format, data structures and sample code without any library dependency to load:
http://paulbourke.net/dataformats/bmp/.
It also contains code to see the loaded BMP in a open gl texture, so pretty much all you need...
Chris Backhouse made a functional little BMP loader (with an eye to using them as OpenGL textures). It's C++, not C, and he admits it's not cross platform. However, it's small and easy to understand, so I thought I'd add the link here:
http://users.ox.ac.uk/~orie1330/bmploader.html
You need some external library to do this (I recommend ImageMagick). The ImageMagick web site also includes documentation and examples.
Check out for OpenCV Library developed by Intel .
If you are tied to the BMP file format, it's pretty simple to look at the header yourself and get the pixels. See this google search. One of the more interesting matches is here. The most counter-intuitive part is that every line of pixels is 4-byte aligned. Also, watch out for compressed BMPs... (My experience is that many third-party tools have trouble with compressed BMPs, so maybe some libraries you encounter will also..)
If you aren't tied to the BMP file format, I recommend libpng. The manual provides some sample code which is pretty clear.
As others suggested you might want to use an external library like SDL. If you want to learn something and do it yourself, see my answer to this very similar question: Getting RGB values for each pixel from a 24bpp Bitmap for conversion to GBA format in C where you'll find C code which prints out each pixel, and have a look at the wikipedia page about bmp files, because it's very good.