## Contrast Stretching for Gray Scale images with MATLAB

When studying “Introduction to Image Processing and Machine vision” and “Bio Medical Engineering and Instrumentation” for the end semester exam, I read a small section related to those two modules which can be easily implemented using MATLAB. “Contrast Stretching” is a simple piecewise linear transformation function which expands the range of intensity of the image to user defined span.

Simple mathematical illustration of the process is as below.

## MATLAB GUI programming (code level) 1.0 – Paint Effect for Images

When surfing in facebook I saw a lot of profile pictures which is modified as painted images. Rather than using the facebook apps I thought to write my own program to do it for me. In this article I’ll try to share my experience on GUI programming in MATLAB without MATLAB GUI guide and the construction of the paint brush effect code.

When studying the image with paint brush effect I noticed that the image colour levels are now limited to a low number, which is most likely a one colour intensity to represent a set of colour. By keeping this in mind I coded a small test program as below.

clc, clear all, close all; im = imread('image_3.jpg'); rateR = 40; rateG = 60; rateB = 50; ima(:,:,1) = cast(rateR*round(im(:,:,1)/rateR),'uint8'); ima(:,:,2) = cast(rateG*round(im(:,:,2)/rateG),'uint8'); ima(:,:,3) = cast(rateB*round(im(:,:,3)/rateB),'uint8'); imshow(ima); imhisto(:,1) = imhist(ima(:,:,1)); imhisto(:,2) = imhist(ima(:,:,2)); imhisto(:,3) = imhist(ima(:,:,3)); figure, plot(imhisto);

Hopefully it got worked, what I have done is,

## Colour Picker for MATLAB Image Processing

When dealing with applications such as image segmentation using colour thresholding, colour replacement I personally faced a problem in dealing with picking an average colour in a set of points in an image or a region in an image. So finally I came up with a small solution which worked on me in my image processing applications on MATLAB. From this article I am going to explain how to make a simple colour picker for small scale MATLAB applications.

## Mean Colour of Discrete points

For picking the points (as discrete points) I used the MATLAB built-in function ‘getpts’. The general for of this function is;

**[x y] = getrect(fig);** where

Metrics x and y will contain the coordinates of column and row points selected by the mouse click. Since the x and y are in double data format we need to convert them to int16 data type for further operations. A right click or the key command <ENTER> must be press to notify the end of picking points for this operation and you can remove last picked points by pressing <BACKSPACE>. And the fig is the image handle which we are used to display the image.

After selecting the points a small for loop can be use to get the sum in-order to obtain the mean colour of the selected points of the image.

1: for i = 1:size(x,1)

2: if((0<x(i))&&(x(i)<=r)&&(0<y(i))&&(y(i)<=c))

` 3: pts = pts + 1;`

` 4: sum = sum + [im(x(i),y(i),1) im(x(i),y(i),2) im(x(i),y(i),3)];`

` 5: end`

6: color = cast(sum/pts,'uint8');

## Digital Image Zooming – Sample Codes on MATLAB

Image zooming or image scaling is another basic operation in computer graphics. In this article I am trying to describe how to implement the image zooming or scaling from our own. Image resize algorithms are try to interpolate the suitable image intensity values for the pixels of resized image which does not directly mapped to its original image. There are three major algorithms for image resizing,

1. Nearest Neighbour Interpolation

You can read more about these methods in Wikipedia and from this web site and also by typing ‘doc imresize’ on MATLAB command prompt which is also the default operation for image resizing. I’ll try to briefly describe what’s going on in the each algorithm and a way to implement it on MATLAB.

### Nearest Neighbour Interpolation

In the nearest neighbour algorithm, the intensity value for the point v(x,y is assigned to the nearest neighbouring pixel intensity f(x,y)which is the mapped pixel of the original image. The logic behind the approximation is as the equation below.

## Interpolation Based method for Directional Derivative Calculation in Image Processing 1.0

Directional derivative calculation can be done by using a number of kernels in image processing. Most of them are fixed and can only use in single direction. This article attempts to discuss and use a geometrical model to as a solution for this situation.

Considering the gradient calculation in image processing, since it is discrete domain, calculations are done by forward and backward differences. Therefore co-efficients of pixels can directly use for built a kernel which can convolve with a given image to determine the gradient.

Consider two pixels *f(x,y) *and *f(x _{r},y_{r})* of an image which are in

**direction with**

__r__**distance. Then the directional derivative can be written as;**

*|*__r__|