Understanding of Matlab (image processing)

Hi. Currently i am doing a proj of image processing. i was told to create a funtion-m file with the function,arguements to display any image etc. but i do not know what are the input and output arguments i should put to display my image? I have tried studying/viewing from lots of videos to understand it but almost all explanation in arguments uses 'points'. I should plot my image first to do the function part? I am really confused, i hope any of you can give a simple explanation for me[ using codes etc ] to let me understand better. [ new to matlab ] thank you very much.

 Accepted Answer

There is an advantage in MATLAB that when a function is created, it can be used as a command in another file. say for example,
%Type this in one file
A=imread('input.jpg'); % Reads input Image
B = imagedisplay(A); % Call the function image display
% Here A, input argument, B output argument
figure, imshow(B);
-------------------------------------------------
%Type this in other file
function [output_img] = imagedisplay(input_img)
output_img = rgb2gray(input_img);
--------------------------------------------------
This function returns an image called ' output_img' and that is displayed in the main program.

16 Comments

can you show me a format of writing statements for image display as example?
if i need to do more conversion instead of only gray scale, i will need more output arguement?
Yes. If your function returns how many variables will be the number of output arguments.
This probably reads the inputImage and displays an Image.
A = imread ('input.jpg');
figure, imshow(A);
can you carry on with the code you gave above with converion from garyscale to binary as example?
Adela
Adela on 20 Sep 2012
Edited: Adela on 20 Sep 2012
where do i call to display the image? & may i know what method of funtion is this? As matlab offers several different types of function. thank you:)
'Yes. If your function returns how many variables will be the number of output arguments.'
- what if i have to use the first output image to covert binary image?
For converting a gray image to binary image you can use this function.
BW = im2bw (I, level);
Here I gray scale image, BW represents the Binary image. As we know that binary image consists of pixel values 0 and 1 only. In a gray scale image pixel values varies from 0 to 255. So 'level' indicates the threshold value.
pixel values greater than level will be assigned with 1.
pixel values lesser than level will be assigned as 0.
yeap! i know that function. but how do i put it together witht the previous code?
Don't you think it would simply be
%Type this in other file
function [output_img] = imagedisplay(input_img)
output_img = rgb2gray(input_img);
output_img = im2bw(output_img);
thanks! but what do i do if i want to display grayscale and binary in main program at the same time?
Well, I'd have two axes and call imshow() to display each image in the desired axes. Does that make sense?
what do you mean by axes??
Oh boy, looks like you need to read the getting started section of the help or look at Doug Hull's tutorial blogs on MATLAB Central. An axes is one of the most basic controls, probably second only to a push button. It's a box on the GUI where you display your results, whether it's a line plot, a bar or pie chart, an image or whatever.
so i'll have to plot my image?
Are you playing with me? Don't you recall that you asked " where do i call to display the image"? Scroll up if you don't. So why do you ask " so i'll have to plot my image?"
And I never said "plot" your image, I said display it with imshow(). But I don't care one way or another what you do with your images - if you display them or not. That's your decision.

Sign in to comment.

More Answers (0)

Categories

Find more on Images 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!