MATLAB: Fading/shading an image

color transitionfaded imageimage processingshade image

Good evening,
I had to darken half of a RGB image in order to recreate an emianopsy. Here is the code I used:
%Loss of left visus
A = imread('lena .bmp');
[x,y,z]=size(A); %dimensions' estraction RGB image
Y=y/2; % halving y axis
HSV = rgb2hsv(A); %conversion to hsv space
%Process the HSV image. This example decrease the brightness of half image by multiplying the V channel by a scale factor.
[h,s,v] = imsplit(HSV); %split hue, saturation and value channels
vFactor = 0.2; %define the scale factor for brightness
% for cicle darken pixels of the left part of the image
for i=1:x
for j=1:Y
v(i,j) = v(i,j)*vFactor;
end
end
HSV_v = cat(3,h,s,v); %reconstrucion of HSV image
%Convert the processed HSV image back to the RGB color space.
Av = hsv2rgb(HSV_v);
figure
imshow(Av)
title('Left emianopsy');
Here is the resulting image:
The separation between the 2 parts of the image is too sharp and marked, so I'd like to obtain a more faded transition between the dark and the coloured side (like a gradient?). How can I obtain a realistic result? like for example the image below:
Thank you in advance

Best Answer

A = imread('lena.bmp'); % read rgb image named 'lena.bmo'
figure(1);imshow(A) % show the original image in figure1
dim = linspace(0,1,512); % create a linear dimming factor across horizontal dimension of the image
dim = repmat(dim,[512 1 3]); % repeat dimming factor for all rows
Adim = uint8(dim.*single(A)); % multiply the dimming factor to the original image and store it in "Adim"
figure(2);imshow(Adim) % show the dim image in figure2