Clear Filters
Clear Filters

C function in Matlab [Mex-file]

2 views (last 30 days)
Esther
Esther on 13 Sep 2012
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 Comments
Jan
Jan on 13 Sep 2012
As long as you do not ask a qeustion, it is hard to help. What is the problem?
Esther
Esther on 13 Sep 2012
my professor wanted me to write in functions. which i do not get what he means too. maybe like C programming?

Sign in to comment.

Answers (1)

Jan
Jan on 13 Sep 2012
Edited: Jan on 13 Sep 2012
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')

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!