MATLAB is a powerful algorithm development environment precisely because you don’t need to worry about implementation details as you create algorithms. However, for the equivalent C code, you have to specify what operations mean. For example, the line of MATLAB code shown above could be translated into this single line of C code that returns B.C. How to convert a matlab code to C-code? Learn more about nodetails, urgent. If you include elements of unlike classes in a matrix, MATLAB ® converts some elements so that all elements of the resulting matrix are of the same type. Data type conversion is done with respect to a preset precedence of classes.
11 Comments
on 14 Jul 2011
image=im2double(image);
G=image(:,:,2);
what is the C-equivalent of the above code ?
on 14 Jul 2011
Display an Image in C code isn't a piece of cake. You can't translate this with ML Coder to C code.
Reading the image can be done with basic file i/o command, fopen, fread, fscanf, etc.
on 14 Jul 2011
ok...but r the following lines of code converted to in C ?
G=image(:,:,2);
on 14 Jul 2011
but what are the above lines of code converted to in C ?
on 14 Jul 2011
Like I said this isn't easy since C is not made for graphic stuff. Maybe google a bit and you will find some ideas how to do it, e.g.:
http://www.codeproject.com/KB/graphics/the_beauty_of_plain_c.aspx
on 14 Jul 2011
could i say that the above lines of code are converting an rgb-image to a yuv image ?
on 14 Jul 2011
no, you simply decompose your image into his Read Green and Blue parts. if you want to go from rgb to yuv you have to do some multiplication:
on 14 Jul 2011
ok...its quite urgent i need to know how the decomposition of image into red,green and blue can be done in C..i know its not easy...but i need to find a way...plzz smeone help me...thanks
on 14 Jul 2011
It will depend on what image type you are trying to read:
.JPG internal format is totally different from .BMP for example.
C does not have the high-level routines to read an image file - you have to read the file format and process it yourself.
Reading the file is easy:
char get_char;
while((get_char=fgetc(input))!= EOF)
...
fclose(input);
in the ... part add your code to process the data. like stated above this will depend on the file format you are trying to read.
on 14 Jul 2011
Thanks Friedrich.Could you help me how an image can be decomposed into red,green and blue in 'C',if in matlab it is given as below:
G=image(:,:,2);
on 14 Jul 2011
could you explain the full workflow you want to have? do you want to read in the file from hdd or do you get it passed in some format? And especially which format (jpg, bmp) do you working with. Like Jan said. post a full detailed discription of what you are like to do.
Sign in to comment.
Matlab To C Code Converter Online
MATLAB Coder™ generates C and C++ code from MATLAB® code for a variety of hardware platforms, from desktop systems to embedded hardware. It supports most of the MATLAB language and a wide range of toolboxes. You can integrate the generated code into your projects as source code, static libraries, or dynamic libraries. The generated code is readable and portable. You can incorporate your existing C code and libraries to get the ultimate efficiency for the key parts of your algorithm, or to reuse code you trust. You can also package the generated code as a MEX-function for use in the MATLAB environment for verification or acceleration.
Embedded Coder® enhances MATLAB Coder for production use with support for code customization, target-specific optimizations, code traceability, and software-in-the-loop (SIL) and processor-in-the-loop (PIL) verification.
Matlab C++ Code
To deploy MATLAB programs as standalone applications, use MATLAB Compiler™ and to generate software components for integration with other programming languages, use MATLAB Compiler SDK™.