Follow on Facebook

header ads

Convolution

Convolution




clear;
close all;
clc;

img = imread('C:\Users\US\Desktop\Image Processing Practice\Images\4.jpg');
img = imresize(img,[256 256]);
img_lab = rgb2lab(img);

figure('units','normalized','outerposition',[0 0 1 1]),
subplot(331),imshow(img),title('Original image');
subplot(332),imshow(img_lab), title('lab image');
img_gray = rgb2gray(img);
subplot(333),imshow(img_gray),title('Gray scale image');
img_gray_th = graythresh(img_gray);

% old method of binarize
% img_bw = im2bw(img_gray,img_gray_th);
% subplot(224), imshow(img_bw),title(['Binary image using gray thresh',num2str(gray_th)]);
% use of binarize func instead of im2bw

img_bw = imbinarize(img_gray,img_gray_th);
subplot(334), imshow(img_bw),title('Binary image using gray thresh');

%% Convolution filter
windowsize = 80;
kernel = ones(windowsize)/windowsize^2;
blurry_img = conv2(single(img_bw), kernel, 'same');
binary_img = blurry_img > img_gray_th; %Rethreshold
subplot(335), imshow(binary_img), title('Smoothened Image after Convolution');










Post a Comment

0 Comments