C function in Matlab [Mex-file]

2 次查看(过去 30 天)
Esther
Esther 2012-9-13
Can someone help me with C function in Matlab? I did these code and my professor wanted me to do in C function in matlab. And is there any good websites that i can learn about matlab functions etc too? thank you.
I = imread('C:\OUTDOOR\456kg.jpg'); %read the image
subplot(3,3,1);imshow(I);
gray = rgb2gray(I); %convert to grayscale
subplot(3,3,2); imshow(gray)
u=fspecial('unsharp',1);
pu=filter2(u,gray);
subplot(3,3,3); imshow(pu/255)
Binary = pu<24; %find a suitable threshold
subplot(3,3,4); imshow(Binary)
Binary = ~Binary; %complement the image
subplot(3,3,5); imshow(Binary)
imwrite(Binary, 'C:\INDOOR\456kgnew.jpg','jpg')
I=imread('C:\INDOOR\456kgnew.jpg'); %read the image
J = imread('C:\INDOOR\456kgnew.jpg');
K = imnoise(J,'salt & pepper',0.02);
L = medfilt2(K);
subplot(3,3,6); imshow(L);
[EDITED, Jan, code formatted]
  2 个评论
Jan
Jan 2012-9-13
As long as you do not ask a qeustion, it is hard to help. What is the problem?
Esther
Esther 2012-9-13
my professor wanted me to write in functions. which i do not get what he means too. maybe like C programming?

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2012-9-13
编辑:Jan 2012-9-13
A function has its own "workspace", which is the set of locally known variables. As explained in the documentation exhaustively (reading the "Getting Started" chapters is recommended!), your can write a function like this:
function [output1, output2, ...] = FunctionName(input1, input2, ...)
"Scripts" are similar, but do not have the above line and they share the workspace of the calling function or script.
For your example:
function MyDisplayFunction(FileName)
I = imread(FileName)
...
Then this is called from the command window or any other function as:
MyDisplayFunction('C:\OUTDOOR\456kg.jpg')

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by