Addition of digital images
Mathematical operations on digital images consist of:
1. Addition
2. Subtraction
3. Multiplication
4. Division
1. Addition
2. Subtraction
3. Multiplication
4. Division
Arithmetic addition:
Arithmetic addition can be done using the following two ways:
1. Pixel to pixel addition of two images
2. Addition of constant to an image
Arithmetic addition can be done using the following two ways:
1. Pixel to pixel addition of two images
2. Addition of constant to an image
Pixel to pixel addition of two images
This is the most simple and straightforward operation applied on two input images of identical dimensions that produces an output image of dimensions identical to that of first two, in which pixel value of the output image is the arithmetic sum of the corresponding pixels from the two input images.
This is the most simple and straightforward operation applied on two input images of identical dimensions that produces an output image of dimensions identical to that of first two, in which pixel value of the output image is the arithmetic sum of the corresponding pixels from the two input images.
Mathematically, the addition operation of two images can be written as: s(x,y)=f(x,y)+g(x,y)
Where
f and g are the two input images of identical dimensions and s is the resulting output image while x and y are the spatial coordinates of the corresponding input and output images.
Where
f and g are the two input images of identical dimensions and s is the resulting output image while x and y are the spatial coordinates of the corresponding input and output images.
If the pixel values in the input image are vectors (e.g. for color images) then the individual components of each of the three channels (i.e., red, green and blue) are added separately from the corresponding input images to produce the output value. More often to reduce the computational time and complexity, programmers prefer to use grayscale images.
Apparently, the resulting output shall depend on the image format of the input images used. For example, if the two input grayscale images are of uint8 class, the output grayscale image will have pixel values within the dynamic range [0, 255] i.e., if the pixel addition of the corresponding two pixels overflows above the maximum value of the dynamic range of the image then the output image will have pixel value equal to the maximum pixel value. For more information on class and their dynamic range click here.
Overflow of pixel addition |
Addition of constant to an image
Alternatively, another popular variant in image addition allows the addition of a constant to every pixel of the input image.
Alternatively, another popular variant in image addition allows the addition of a constant to every pixel of the input image.
Mathematically, the addition of a constant to an image can be expressed as:
s(x,y) = f(x,y) + c
Where f is the input image, c is the constant and s is the resulting output image while x and y are the spatial coordinates of the input and output images. Addition of a constant to an image is often referred as brightness increment operation.
s(x,y) = f(x,y) + c
Where f is the input image, c is the constant and s is the resulting output image while x and y are the spatial coordinates of the input and output images. Addition of a constant to an image is often referred as brightness increment operation.
Octave code:
1. Addition of two images(pixel to pixel addition)
clc;
clear all;
close all;
f = imread("ubuntu.jpg");
g = imread("ubuntulogo.png");
[h1 w1 c1] = size(f);
[h2 w2 c2] = size(g);
if h1==h2 && w1==w2
if c1 == 3
f = rgb2gray(f);
end
figure, imshow(f); title("Grayscale image 1");
if c2 == 3
g = rgb2gray(g);
end
figure, imshow(g); title("Grayscale image 2");
s = imadd(f,g,"uint8");
figure, imshow(s); title("Addition of two images using imadd command");
for x = 1 : h1
for y = 1 : w1
t(x,y) = f(x,y)+g(x,y);
end
end
figure, imshow(t); title("Addition of two images using pixel to pixel addition");
else
msgbox("Choose images of same dimension");
end
clc;
clear all;
close all;
f = imread("ubuntu.jpg");
g = imread("ubuntulogo.png");
[h1 w1 c1] = size(f);
[h2 w2 c2] = size(g);
if h1==h2 && w1==w2
if c1 == 3
f = rgb2gray(f);
end
figure, imshow(f); title("Grayscale image 1");
if c2 == 3
g = rgb2gray(g);
end
figure, imshow(g); title("Grayscale image 2");
s = imadd(f,g,"uint8");
figure, imshow(s); title("Addition of two images using imadd command");
for x = 1 : h1
for y = 1 : w1
t(x,y) = f(x,y)+g(x,y);
end
end
figure, imshow(t); title("Addition of two images using pixel to pixel addition");
else
msgbox("Choose images of same dimension");
end
Output:
Input grayscale images with identical dimension |
Result of addition of two images |
2. Addition of a constant to an image
clc;
clear all;
close all;
f = imread("google.jpg");
[h1 w1 c1] = size(f);
c = 25; %% Constant to be added to every pixel of input image
if c1 == 3
f = rgb2gray(f);
end
s = imadd(f,25,"uint8");
for x = 1 : h1
for y = 1 : w1
t(x,y) = f(x,y) +25;
end
end
figure, imshow(f); title("Grayscale image");
figure, imshow(s); title("Addition of constant to an image");
figure, imshow(t); title("Addition of a constant to an image");
clc;
clear all;
close all;
f = imread("google.jpg");
[h1 w1 c1] = size(f);
c = 25; %% Constant to be added to every pixel of input image
if c1 == 3
f = rgb2gray(f);
end
s = imadd(f,25,"uint8");
for x = 1 : h1
for y = 1 : w1
t(x,y) = f(x,y) +25;
end
end
figure, imshow(f); title("Grayscale image");
figure, imshow(s); title("Addition of constant to an image");
figure, imshow(t); title("Addition of a constant to an image");
Output:
Input grayscale image |
Result of addition of a constant to an image(brightness increment) |
Comments
Post a Comment