% These are file comments. % If you are not certain what a MATLAB function does, type % >> help fName % at the console window. Alternately, you can use the online help. % The first line for an m-file function begins with (something like) function r = fName(a1) % r is a return value, fName is the function name and a1 is the argument % This function is called from the console with % >> x = fName('im1.tiff'); % This next statement reads the image data in from the image file. % It is assumed that a1 is in a string format, e.g. 'im.tiff' im = imread(a1,'TIFF'); % This statement displays the image imagesc(im); % If the image is grayscale, you will need to change the colormap as below colormap gray; % Gets a single mouse click input from the figure [x,y,b] = ginput(1) % Leaving off the semicolon causes the values to stream on the console window. % This is useful for debugging % The size function returns the number of rows/cols in an array [row,col] = size(im); % This is the format for a "for" loop. % This loop sets all of the elements of the first column to 0 for i=1:row % Parentheses are the array operator, and it is (row,col) format im(i,1)=0; % All code blocks must end with "end" end % You could achieve the same effect by doing im(1:end,1)=0; % Or im(:,1)=0; % These are MUCH FASTER than using for loops. % This loop demos the "if-else" statement. The else part is optional. for i=1:col if im(1,i)>100 im(1,i) = 255; else im(1,i) = 0; end end % Again a MUCH faster implementation would be im(1,:) = 255*(im(1,:)>100); % Dummy assignment for return value r = 0;