Alternative Tool to Matlab... Octave in Image Processing
Octave is a free open source program offers services relatively similar to Matlab.
In order to be able to use Octave in Image
processing application, you will need to install image package, which can
be done easily by typing the following commands in the command window:
Pkg list
pkg install -forge
general control signal image
|
·
Each time you want to use image library, you have to load the image
package, by typing the following command:
Pkg load image % only in Octave, in Matlab it is
already automatic added
|
- Some important commands:
Command function
|
Command syntax
|
Clear command window
|
clc
|
Load image
|
imread('H:\Octave-4.4.0\samples\myImage.png')
|
Show an image
|
imshow(im)
|
To get the size of a matrix
|
size(im)
> disp(size(im))
|
To plot some matrices
|
>> plot(imgreen(210,:))
|
To display the data type of
the matrix
|
disp(class(im))
|
To substract 2 images without
losing pixels values which will be rounded to 0 because they are negative
|
Imabsdiff(image1,image2)
|
To generate a Gausian noise with Standard Deviation between 1 and -1,
And you can specify the
number of samples
To generate a Gausian noise
to apply it on an image, we can generate a noise matrix with the same size of
our image
If we multiply this noise
matrix with a scalar then the standard deviation will be changed
|
Number= randn() // will
generate a random number between -1 and 1
>> rand_n=randn()
rand_n = 0.083304
>> rand_Vec=randn([1
10]) //will generate a vector of 10 elements between 1 and -1
rand_Vec =
0.242985
-0.150862 -0.856364 -1.788098
0.102084 1.030511 0.267734
-0.102228 0.603328 -0.020853
Noise=randn([1 100])
//generate a vector from 1 to 100
noise=randn(size(peng));
|
To show how samples are
distributed between values, we can use hist where first input is the matrix
and second input is the x-axis
Hist returns 2 values:
N: number of elements in each
sample point
X: the sample points (x-axis)
Then using plot(x,n), we can
see how the Gausian distribution is distributed
|
Noise=randn([1 100]);
Hist(noise,[-3 -2 -1 0 1 2
3]);
>> [n,x]=hist(noise,[-3 -2 -1 0 1 2 3])
n =
1
11 23 36
23 5 1
x =
-3
-2 -1 0
1 2 3
|
To generate number of samples
between 2 values, use linspace:
|
Linspace(-3,3,100) // collect
samples between -3 and 3 with 100 sample
>> noise=randn([1
1000]);
>>
[x,n]=hist(noise,linspace(-3,3,21));
>> plot(n,x)
|
Create a Gaussian filter
|
h=fspecial('gaussian',
kernel_size,sigma);
|
Apply the filter
on the image
|
out_img=imfilter(img,h);
|
·
Comments
Post a Comment