Matlab offset values and histograms
The semester slowly moves to its logical ending - the summer, and the only question I have is, if I’m going to use Matlab after finishing Data Image Processing lectures or not.
But since, I’m still using it, here is going to be one of the last projects for DIP lesson - offset changes of an image, with later on processing of histograms.
Comparing Matlab erode and dilate functions - offset procedure doesn’t effect the neighbouring pixels - all the actions are performed on each pixel respectively.
For changing offset value of an image we need to:
- Create a matrix of an initial image;
- Create a colour array for mapping pixels of the same colours (will be used for histogram);
- Accept the offset value from the user;
- And, of course, recalculate it all!
Since we’re going to work with grey scale image, we have up to 255 colours from black to white. Later on, I’ll use the picture which was taken close to the institute.
Ia = imread(’a.jpg’);
disp(’..Image “A” is loaded’)
%Initializing the colour array
arrA = zeros([1 255]);
Since the image has 683×1024 size, we’re going to use the nested loop to match all the colours and store its pixels into the array:
for n=1: 1024
%Storing repetetive color indexes in color array.
for i=1: 255
%Placing colors into color arrays for 3 images respectively.
arrA(1,i) = arrA(1,i) +1;
end
end
end
end
After eliminating the matrix picture, and entering the offset value, we can create an offset.m function file, where the rest of the calculations will take place. For it, we’ll need to initiate a new matrix, of the same size, and another colour array, which will hold transformed pixel colours, and their quantities, to show the difference in the histograms:
for j=1: 1024
for k=1: 255
if k == Mtrx(i,j)
newArr(1,k) = newArr(1,k) + 1;
end
end
end
end
%…
figure,imshow(y); title(’Initial Image’);
figure,imshow(Mtrx); title(’Result of Offset.jpg’);
disp(’Histograms…’)
figure,plot(z);title(’Initial Histogram’);
figure,plot(newArr); title(’Resulting Histogram’);
I’ve mentioned the main states of the calculation, but if you need to get really into the sources, simply download the source files, where three images have been processed, and enhanced with scaling function source files. For more complicated offset functionality, you may be interested in the offset filter made in Boston University.

