3 fixImage.m
[15 marks]
You know from your labs that a grayscale image is simply a matrix where the elements are usually in the range of of 0 to 255. Suppose that you are using some Matlab code that another student has given you to process some grayscale images. After testing their code you realize that their code sometimes changes values in the image to values less that 0 and sometimes changes values in the image to greater than 255. You need to write a function that repairs the processed image so that values in the image less than 0 are set to 0 and values greater than 255 are set to 255.
Complete the following function:
function J = fixImage(I)
%FIXIMAGE Fix grayscale image values
% J = fixImage(I) returns a new grayscale image
% equal to I except that values less than 0 are replaced
% with 0 and values greater than 255 are replaced with
% 255.
end
3.1 Constraints
- you must use a loop or loops to iterate over the elements of the matrix to solve this problem
- the only Matlab functions you are allowed to use are
size
,numel
, andzeros
3.2 Example usage
I = [-1 0 100;
-25 150 255;
5 300 99];
J = fixImage(I);
In the above example J
should be equal to the matrix
[0 0 100;
0 150 255;
5 255 99];