Skip to content

Commit

Permalink
image processing basics and other stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
sourabh2k15 committed Oct 23, 2015
1 parent 6b3f5b3 commit c162ed2
Show file tree
Hide file tree
Showing 34 changed files with 321 additions and 0 deletions.
13 changes: 13 additions & 0 deletions basics/firstone.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
%hold example
a = linspace(1,2*pi);
b = sin(a);
c = sin(a*2);
d = sin(a*3/2);
% ab teeno p se comment htane p bhi sirf 3rd waala graph bchta h so if
% someone wanted all 3 graphs nt possible without hold , unless he plans to
% use subplot
hold on;

plot(a,b,'green');
plot(a,c,'magenta');
plot(a,d,'cyan');
14 changes: 14 additions & 0 deletions basics/subplotexample.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
%subplot example
a = linspace(1,2*pi);
b = sin(a);
c = sin(a*2);
d = sin(a*3/2);

subplot(3,1,1);
plot(a,b,'green');

subplot(3,1,2);
plot(a,c,'magenta');

subplot(3,1,3);
plot(a,d,'cyan');
2 changes: 2 additions & 0 deletions doubts.txt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1) contrast enhancement by histogram equalization
2) imshow , double , bit planes
8 changes: 8 additions & 0 deletions imageprocessing/bitmap.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
clc;clear all;
img = imread('images/god.jpg');
img = rgb2gray(img);
x = bitget(img,8);

x = uint8(x*255);
imshow(x);
imwrite(x,'images/bitplane.jpg');
32 changes: 32 additions & 0 deletions imageprocessing/colormapexample.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
clc;clear all;

mycolormap = [];

for i = 1:32
mycolormap(i,1) = (i)/255;
mycolormap(i,2) = (i)/255;
mycolormap(i,3) = 0;
end;

for i = 33:64
mycolormap(i,1) = 0;
mycolormap(i,2) = (i/2)/255;
mycolormap(i,3) = (i/2)/255;
end;

for i = 65:96
mycolormap(i,1) = (i/3)/255;
mycolormap(i,2) = 0;
mycolormap(i,3) = (i/3)/255;
end;
img = imread('images/god.jpg');
%colormap(mycolormap);

colormap hsv;

cmap = colormap;
indexedimg = rgb2ind(img,cmap);
imshow(indexedimg);


%imwrite(indexedimg,'images/darklord.jpg');
8 changes: 8 additions & 0 deletions imageprocessing/edge_detection.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
clc;clear all;
img=imread('images/god.jpg');
I=rgb2gray(img);
BW1 = edge(I,'sobel');
BW2 = edge(I,'canny');
figure;
imshowpair(BW1,BW2,'montage') %new function for displaying multiple graphs!
title('Sobel Filter Canny Filter');
14 changes: 14 additions & 0 deletions imageprocessing/experiment.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
% we'll cretae our own image data array
a = [];

k = 100;

for i = 1:k
for j = 1:k
a(i,j,1) = 20 + floor(rand()*235);
a(i,j,2) = 30 + floor(rand()*225);
a(i,j,3) = floor(rand()*255);
end;
end;
grayimg = rgb2gray(a);
[a,b] = imhist(grayimg);
15 changes: 15 additions & 0 deletions imageprocessing/filters.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
clc;clear;

img=imread('images/god.jpg');
[x, map]=rgb2ind(img,256);
f1 = ones(4)/16;
image=filter2(f1, x);

subplot(121);
imshow(img);
subplot(122);
imshow(image);
%used indexed image, but no idea about the result
%use ye waala filter for grayscale, rgb me average k liye alag filter hai


31 changes: 31 additions & 0 deletions imageprocessing/filters4rgb.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
img=imread('images/god.jpg');

radius=27;
h=fspecial('disk',radius);

edge=fspecial('sobel');


image1=imfilter(img,h,'replicate');
image2=imfilter(img,edge,'replicate');

subplot(221);
imshow(img);
subplot(222);
imshow(image1);
subplot(223);
imshow(image2);

%sobel is used in edge detection

img=imnoise(img,'salt & pepper',0.2);
%subplot(224); imshow(img);
imr=medfilt2(img(:,:,1),[3 3]);
imgr=medfilt2(img(:,:,2),[3 3]);
imb=medfilt2(img(:,:,3),[3 3]);
image3=cat(3, imr, imgr, imb);
subplot(224);
imshow(image3);



34 changes: 34 additions & 0 deletions imageprocessing/imagebasics.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
% it is read into a 3d array
img = imread('god.jpg');

a = size(img);
%display(a(1,2));
% display displays vars to the command window

padding = zeros(a(1,1),a(1,2));

% the colon serves as a wildcard entry so that all values in the red are
% selected in all rows and columns
redimg = cat(3,img(:,:,1),padding,padding);
blueimg = cat(3,padding,img(:,:,2),padding);
greenimg = cat(3,padding,padding,img(:,:,3));

% imshow takes the raw image array data and makes it into a figure ,
subplot(1,3,1);
imshow(redimg);

subplot(1,3,2);
imshow(greenimg);

subplot(1,3,3);
imshow(blueimg);

% how to multiline comment in matlab ? %{%} this is a rarely used feature
figure ; imshow(redimg);
figure ; imshow(blueimg);
figure ; imshow(greenimg);

imwrite(redimg,'redgod.png');
imwrite(greenimg,'greengod.png');
imwrite(blueimg,'bluegod.png');

Binary file added imageprocessing/images/averged.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imageprocessing/images/bhootiy2agod.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imageprocessing/images/bhootiyagod.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imageprocessing/images/bing.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imageprocessing/images/bitplanegod.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imageprocessing/images/bluegod.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imageprocessing/images/bwgod.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imageprocessing/images/darklord.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imageprocessing/images/god.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imageprocessing/images/graygod.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imageprocessing/images/grayscale.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imageprocessing/images/greengod.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imageprocessing/images/redgod.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imageprocessing/images/ye_waala_m_nkiya.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions imageprocessing/imagetransformations.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
img=imread('images/god.jpg');

colormap jet;
cmap1 = colormap;

colormap default;
cmap2 = colormap;

colormap gray;
cmap3 = colormap;

colormap winter;
mycmap = colormap;

%[indimg,map] = rgb2ind(img,150);

figure ;
imshow(rgb2ind(img,cmap3));
colormap(cmap3);

figure;
imshow(rgb2ind(img,cmap2));
colormap(cmap2);

figure;
imshow(rgb2ind(img,cmap1));
colormap(cmap1);

figure;
imshow(rgb2ind(img,mycmap));
colormap(mycmap);

%imwrite(imdimg,'images/oilpainting_255bins.jpg');
16 changes: 16 additions & 0 deletions imageprocessing/invertcolors.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
img = imread('images/god.jpg');
a = size(img);

for i = 1:a(1,1)
for j = 1:a(1,2)
% manipulating these relation infinite number of effects can be
% formed
% for invert change this to img(i,j,k) = 255 - img(i,j,k);
img(i,j,1) = (img(i,j,1) * .393) + (img(i,j,2) *.769) + (img(i,j,3) * .189);
img(i,j,2) = (img(i,j,1)* .349) + (img(i,j,2) *.686) + (img(i,j,3) * .168);
img(i,j,3) = (img(i,j,1) * .272) + (img(i,j,2) *.534) + (img(i,j,3) * .131);
end;
end;

imshow(img);
%imwrite('images/invertedgod.jpg');
2 changes: 2 additions & 0 deletions imageprocessing/makefile.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
echo ""> newfile.m
5 changes: 5 additions & 0 deletions imageprocessing/modfloor.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function f = modfloor(n,k)
f = mod(floor(n/2),2);
for i=1:k-1
f = mod(floor(f/2),2);
end
5 changes: 5 additions & 0 deletions imageprocessing/randomexp.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
a = linspace(1,2*pi);
b = sin(a);
c = sin(2*a);

plot(a,b,a,c);
13 changes: 13 additions & 0 deletions imageprocessing/randomshit.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
img = imread('images/god.jpg');
gray = rgb2gray(img);

imadj = imadjust(img,[0,0.85],[]);
k = 5;
for i=1:k*k
subplot(k,k,i);
imadj = imadjust(imadj,[0,0.85],[]);
imshow(imadj);
end;

% ruk what are we trying to do just jot it down agr 2*2 plots h
% to i runs from 1:2 so we need subplot(2,2,1/2/3/4) 1+0,1+1,2+1,2+2
13 changes: 13 additions & 0 deletions imageprocessing/rgb2gray_code.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
img = imread('images/god.jpg');
a = size(img);

for i = 1:a(1,1)
for j=1:a(1,2)
img(i,j,1) = 0.2126*img(i,j,1) +0.7152*img(i,j,2)+0.0722*img(i,j,3);
img(i,j,2) = 0.2126*img(i,j,1) +0.7152*img(i,j,2)+0.0722*img(i,j,3);
img(i,j,3) = 0.2126*img(i,j,1) +0.7152*img(i,j,2)+0.0722*img(i,j,3);
end
end;

imshow(img);
imwrite(img,'images/grayscale.jpg')
29 changes: 29 additions & 0 deletions imageprocessing/rgb2grayexample.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
img = imread('images/god.jpg');
grayimg = rgb2gray(img);
bwimage = im2bw(img);

a = size(img);

padding = zeros(a(1,1),a(1,2));
redimg = cat(3,img(:,:,1),padding,padding);
blueimg = cat(3,padding,img(:,:,2),padding);
greenimg = cat(3,padding,padding,img(:,:,3));

[yRed,x] = imhist(img(:,:,1));
[yGreen,x] = imhist(img(:,:,2));
[yBlue,x] = imhist(img(:,:,3));

hold on;
plot(x,yRed,'red');
plot(x,yGreen,'green');
plot(x,yBlue,'blue');
%{
subplot(1,3,1);
plot(x,yRed,x,yGreen,x,yBlue);
subplot(1,3,2);
imhist(grayimg);
subplot(1,3,3);
imhist(bwimage);
%}
22 changes: 22 additions & 0 deletions imageprocessing/testfilters.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
clc; clear all;
img=imread('images/god.jpg');
img=rgb2gray(img);
imgd=im2double(img);

imgd=imnoise(imgd, 'salt & pepper', 0.02); %0.02 gives density of noise
f=ones(3,3)/9;
image=filter2(f,imgd);
subplot(221);
imshow(imgd);
subplot(222);
imshow(image);
%works!!!!

%mean filter just blurrs the image, not much useful
%trying median filter

betterimage=medfilt2(imgd);
subplot(223);
imshow(betterimage);


12 changes: 12 additions & 0 deletions resources.txt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
octave docs

https://www.gnu.org/software/octave/doc/interpreter/

matlab

http://www.bogotobogo.com/Matlab/

speech processing http://www.mathworks.com/matlabcentral/profile/authors/4428430-speech-processing


https://sites.google.com/site/butwhymath/m/convolution ( convolution )

0 comments on commit c162ed2

Please sign in to comment.