Question
Solve using matlab
4. Create a 200x200 matrix of random integers in the range [0, 64]. Display the image/matrix with image(). Write a function to take the image and contrast stretch the image from [0,255]. Display the new image with image() Display both images with the 256-element gray colormap. 5. Form the histograms of the two images created in Problem #4. Display them on the same graph. Use the function, n, v hist(x, 65) 6. Open the standard image, 'cameraman.tif' with the imread() function. Brighten the image by a factor of 2 display the image with a 256-element gray colormap. Darken the image by a factor of 2 and display the image with the same 256-element gray colormap. You may have to ensure that all output values lie in the [0,255]. 7. Form the histograms of the two images created in Problem #6. Display them on 8. Again, open the standard image, 'cameraman.tif'. Write a function using 9. Again, open the standard image, 'cameraman.tif'. Write a function using 10,1] and after it is processed scale back to [0,255] and the same graph. Again, use the function, [n,v] -hist (x,200). for-loops to create the negative of the image. Display both images. for-loops to create a gamma corrected image. Use a gamma value of 1.5. Display both the original and corrected image. You will have to make the image round to the nearest integer. 10,Form the histograms of the two images created in Problem #9. Display them on the same graph. Use the function, [n, v] hist (x, 200). 11.Create a 20-element long vector of random integers from 1-100. Write your own sorting routine to sort the values from largest to smallest. Verify your routine by sorting the vector with Matlab's sort (x) routine and taking the difference and summing the error vector (i.e., sum(error)).
Explanation / Answer
ANSWER TO FIRST FOUR PARTS OF THE QUESTION
; supresses output.
Copy paste the codes in MATLAB new file and run the file.
4.
imshow(r);
figure; title('Original'); imshow(uint8Image); % Original Image
figure; title('Contrast improve'); imshow(uint8Image1); %figure displays in a new window.
5.
x=imhist(uint8Image); % finds histogram of original image
y=imhist(uint8Image1); % finds histogram of contrast image
6.
A= imread('cameraman.tif'); % reads image into matrix
A1= rgb2gray(A); % coverts A to gray image
title('Original Image'); imshow(A1);
A2= A1 * 2; % brightens the image by a factor of 2
figure; title('Brightened Image'); imshow(A2); % figure displays a new figure
A3= A1 * 0.5; % darkens the image by a factor of 2
figure; title('Darkened Image'); imshow(A3);
7.
x=imhist(A2); % finds histogram of brightened image
y=imhist(A3); % finds histogram of darkened image