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 Exchange에서 Data 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