%% importing image file [fname path] = uigetfile('*.jpg'); fname = strcat(path,fname); subplot(3,3,1); im = imread(fname); imshow(im); %% color channels imR = im; imR(:,:,2:3) = 0; subplot(3,3,2); imshow(imR); title('red channel'); imG = im ; imG(:,:,1) = 0 ; imG(:,:,3) = 0 ; subplot(3,3,3); imshow(imG); title('green channel'); imB = im; imB(:,:,1:2) = 0 ; subplot(3,3,4); imshow(imB); title('blue cahnnel'); %% gray conversion imGrayM = rgb2gray(im); subplot(3,3,5); imshow(imGrayM); title('gray conversion'); %% gray conversion by color channel imGrayRed = im(:,:,1); subplot(3,3,6); imshow(imGrayRed); title('gray red'); %% gray conversion by formula imGrayFormula = 0.2989 * im(:,:,1) + 0.5870 * im(:,:,2) + 0.1140 * im(:,:,3) ; subplot(3,3,7); imshow(imGrayFormula);, title('gray formula'); %% thresholding a = ThresholdingFirst(imGrayM); subplot(3,3,8); imshow(a); title('thresholded image'); %% histogram of an image subplot(2,3,1); im = imread('cat.jpg'); imshow(im); subplot(2,3,2); im2 = rgb2gray(im); imshow(im2); subplot(2,3,3); imhist(im2); %% histogram equalization subplot(2,3,4); j = histeq(im2); imshow(j); subplot(2,3,6); imhist(j); %% otsu threshold I = imread('cat.jpg'); I2 = rgb2gray(I); level = graythresh(I2); BW = im2bw(I2,level); imshow(BW);