How to convert a matlab code to C-code ?

Its quite urgent,can anybody tell me how to convert a matlab code to C-code ???

回答 (4 件)

Jan
Jan 2011 年 7 月 14 日

2 投票

If it is urgent for you, take the time to explain the problem with all needed details.
The separation of a 3D-RGB array is not complicated in C, if the array has the same format as in Matlab. But is this the case? How did you obtain the pixel values in C? We cannot guess such details...
For an [M x N x 3] RGB array of type UINT8, the first [M x N] bytes are the red channel, then the next [M x N] bytes the green channel, and the last [M x N] bytes are the blue channel.

2 件のコメント

keethi2
keethi2 2011 年 7 月 14 日
Hey Sorry guys..i should have posted the entire problem with details..
Basically i have a jpeg image,i
1. Read in the jpeg image
2. convert the image to double data-type.
3. Decompose the image into red,green and blue parts.
4. perform some processing on these red,green and blue parts separately.
in Matlab i have written as below:
image=imread(c);
image=im2double(image);
R=image(:,:,1);
G=image(:,:,2);
B=image(:,:,3);
-----
process R,G,B parts...
-------
Im trying to convert the entire matlab code to C-code.It would be great if i could get help on above code as explained..thanks
Friedrich
Friedrich 2011 年 7 月 14 日
編集済み: DGM 2023 年 2 月 14 日
Since jpeg is a compress format it is stored in a more complex way you, reading it is a bit tricky. For the format see here:
I never have done this and I can't help you with posting code. Sorry

サインインしてコメントする。

Titus Edelhofer
Titus Edelhofer 2011 年 7 月 13 日

1 投票

Hi,
Titus

1 件のコメント

keethi2
keethi2 2011 年 7 月 14 日
which means i need to download the matlab coder to convert the code ??

サインインしてコメントする。

Friedrich
Friedrich 2011 年 7 月 14 日

0 投票

Hi,
Yes, download and maybe buy it if you dont have it. But not all functions are supported for code generation. for a list see here:

10 件のコメント

keethi2
keethi2 2011 年 7 月 14 日
image=imread(c);
image=im2double(image);
R=image(:,:,1);
G=image(:,:,2);
B=image(:,:,3);
what is the C-equivalent of the above code ?
Friedrich
Friedrich 2011 年 7 月 14 日
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.
keethi2
keethi2 2011 年 7 月 14 日
ok...but r the following lines of code converted to in C ?
R=image(:,:,1);
G=image(:,:,2);
B=image(:,:,3);
Friedrich
Friedrich 2011 年 7 月 14 日
編集済み: DGM 2023 年 2 月 14 日
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.:
keethi2
keethi2 2011 年 7 月 14 日
could i say that the above lines of code are converting an rgb-image to a yuv image ?
Friedrich
Friedrich 2011 年 7 月 14 日
編集済み: DGM 2023 年 2 月 14 日
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:
keethi2
keethi2 2011 年 7 月 14 日
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
Friedrich
Friedrich 2011 年 7 月 14 日
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:
FILE *input;
char get_char;
input = fopen("myimage.bmp", "rb");
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.
keethi2
keethi2 2011 年 7 月 14 日
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:
R=image(:,:,1);
G=image(:,:,2);
B=image(:,:,3);
Friedrich
Friedrich 2011 年 7 月 14 日
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.

サインインしてコメントする。

Walter Roberson
Walter Roberson 2011 年 7 月 14 日

0 投票

Use one of the available software libraries such as libjpeg to read the file. The details of accessing the returned data will then depend upon the format returned by the library.

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

質問済み:

2011 年 7 月 13 日

編集済み:

DGM
2023 年 2 月 14 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by