When the lens size is smaller than the dimensions of the actual image sensor, or inadequately covering it, it leads to an effect whereby the center of the image is clear, and a fading/darkening of the image borders is seen. This effect is commonly referred to as the Vignetting Effect. In graphics, it is used to de-emphasize the distracting background, and shed light on the foreground objects.
Example
|
|
|
|
|
|
|
|
MATLAB Code
% *************************************************************************
% Title: Function-Introduce Vignetting effect to the image
% Author: Siddhant Ahuja
% Created: September 2008
% Copyright Siddhant Ahuja, 2008
% Inputs: Input Image (var: inputImage), Scale Change level (var:
% scaleLevel) Valid values for scale change should go from 0.1 to 1
% Outputs: Vignetting effect added image (var: vignettImg, Time taken (var: timeTaken)
% Example Usage of Function: [vignettImg, timeTaken]=funcVignettingEffect('Baby1LeftColor.png', 0.5);
% *************************************************************************
function [vignettImg, timeTaken]=funcVignettingEffect(inputImage,scaleLevel)
% Read the input image
try
% Read an image using imread function
inputImage=imread(inputImage);
% grab the number of rows, columns, and channels
[nr, nc, nChannels]=size(inputImage);
% Grab the image information (metadata) of input image using the function imfinfo
inputImageInfo=imfinfo(inputImage);
% Determine if input left image is already in grayscale or color
if(getfield(inputImageInfo,'ColorType')=='truecolor')
colored=1;
else if(getfield(inputImageInfo,'ColorType')=='grayscale')
colored=0;
else
error('The Color Type of Left Image is not acceptable. Acceptable color types are truecolor or grayscale.');
end
end
catch
% if it is not an image but a variable
inputImage=inputImage;
% grab the number of channels
[nr, nc, nChannels]=size(inputImage);
if(nChannels)>1
colored=1;
else
colored=0;
end
end
if scaleLevel <= 0
error('Scale value must be > 0');
end
vignettImg=inputImage;
tic; % Initialize the timer to calculate the time consumed.
imgCntX = nc/2;
imgCntY = nr/2;
maxDistance = sqrt (imgCntY^2 + imgCntX^2);
if(colored==1)
for (i=1:nr)
for (j=1:nc)
dis = sqrt (abs(i-imgCntY)^2 + abs(j-imgCntX)^2);
%% reduce brighness of pixel based on distance from the image center
vignettImg(i,j,1) = vignettImg(i,j,1)* (1 - (1-scaleLevel)*(dis/maxDistance) );
vignettImg(i,j,2) = vignettImg(i,j,2)* (1 - (1-scaleLevel)*(dis/maxDistance) );
vignettImg(i,j,3) = vignettImg(i,j,3)* (1 - (1-scaleLevel)*(dis/maxDistance) );
end
end
else
%gray
for (i=1:nr)
for (j=1:nc)
dis = sqrt (abs(i-imgCntY)^2 + abs(j-imgCntX)^2);
%% reduce brighness of pixel based on distance from the image center
vignettImg(i,j) = vignettImg(i,j)* (1 - (1-scaleLevel)*(dis/maxDistance) );
end
end
end
% Stop the timer to calculate the time consumed.
timeTaken=toc;






Hi,
This is somewhat off-topic — but what do you use to put syntax-highlighted Matlab code into your blog?.. Is it a WordPress plugin of sorts?.. I’d much appreciate it if you could email me the info. I just started my blog, and would like to play around with embedding bits of code.
Hi
The latest version of MATLAB supports a rich text box style editor for writing code. I just copy the code from there and paste in the software that i had custom built for this purpose, called: Code Formatter. This was written in C#, and all it does is takes the colors and style of fonts pasted in the rich text box and generates an HTML code compatible with wordpress blogs. You can find it in: http://siddhantahuja.wordpress.com/tag/code-format/