Need help in the Color image fusion based on Pixel Average method
2 views (last 30 days)
Show older comments
Dear all, Here I added My Script on Color Image fusion based on Pixel Average method. I took an image for contrast enhancement purpose, there I apply CLAHE on R plane oof the image, also convert the same RGB image to HSV and apply CLAHE on S & V Planes. Then again merge modified R plane with G & B planes as RGB image, modified S & V planes with H plane as HSV image. Pixel Average based fusion applied on those RGB & HSV images, but I could not get the color image as expected. Your Kind suggestions are Welcome and Appreciated
clc
clear all;
close all;
rgbImage=imread('greens.jpg');
% Separate image into RGB
r = rgbImage(:, :, 1); % Red image.
g = rgbImage(:, :, 2); % Green image.
b = rgbImage(:, :, 3); % Blue image.
% Apply CLAHE to R Plane
Rmod = adapthisteq(r);
rgbImage_out = cat(3,Rmod,g,b);
rgbImage_out = double(rgbImage_out );
[m,n]=size(r);
figure(1)
imshow(rgbImage_out);
title('RGB Enhanced')
%%
% RGB to HSV Conversion
hsv = rgb2hsv(rgbImage);
h = hsv(:, :, 1); % Hue image.
s = hsv(:, :, 2); % Saturation image.
v = hsv(:, :, 3); % Value (intensity) image.
%%
% Apply CLAHE to S & V Planes
Smod = adapthisteq(s);
Vmod = adapthisteq(v);
hsv_out = cat(3,h,Smod,Vmod);
figure(2)
imshow(uint8(hsv_out));
title('HSV Enhanced')
%%
% Convert HSV to RGB again
rgb_hsv = hsv2rgb(hsv);
figure(3)
imshow(rgb_hsv);
title('rgb_hsv Enhanced')
%%
% Fusion of Two Images
for i=1:m
for j=1:n
y1(i,j)=0.5*rgbImage_out(i,j)+0.5*rgb_hsv(i,j); % Simple image fusion method based on weighted average
end
end
figure(4)
imshow(uint8(y1));
title('Color image Contrast Enhanced')
0 Comments
Accepted Answer
DGM
on 22 Nov 2021
Edited: DGM
on 22 Nov 2021
Let's start with this:
rgbImage=imread('greens.jpg');
% Separate image into RGB
[r g b] = imsplit(rgbImage);
% Apply CLAHE to R Plane
Rmod = adapthisteq(r);
rgbImage_out = cat(3,Rmod,g,b);
[m,n]=size(r);
figure(1)
imshow(rgbImage_out);
title('RGB Enhanced')
% RGB to HSV Conversion
hsv = rgb2hsv(rgbImage);
[h s v] = imsplit(hsv);
% Apply CLAHE to S & V Planes
Smod = adapthisteq(s);
Vmod = adapthisteq(v);
hsv_out = cat(3,h,Smod,Vmod); % this is an HSV image
figure(2)
imshow(hsv_out); % pay attention to both class and data scale
title('HSV Enhanced')
% Convert HSV to RGB again
rgb_hsv = hsv2rgb(hsv);
figure(3)
imshow(rgb_hsv);
title('rgb hsv Enhanced')
% Fusion of Two Images
weightA = 0.5; % this allows you to change the relative balance
y1 = weightA.*im2double(rgbImage_out) + (1-weightA).*im2double(rgb_hsv);
figure(4)
imshow(y1);
title('Color image Contrast Enhanced')
Viewing anything other than RGB
Viewing an HSV image like that is just going to look like rainbow nonsense, since it's rendered as false RGB. It coincidentally works because the data ranges are appropriate, but if this were being done in some other color model (e.g. Lab, LCHab), then gross clipping would occur. Just keep in mind that all your display tools are RGB.
Boilerplate note on class and data range
Pay attention to both class and data scaling. The representation of image data depends on an assumption of the nominal data range (i.e. what black is, what white is). This is implied by the numeric class. For integer classes, this is simply the full range supported by the bit width (e.g. [0 255] for uint8). All floating-point classes are assumed to be unit scale ([0 1]), just the same as logical images.
When you take a uint8 image and cast it with double(), you end up with a bunch of supramaximal data -- all the data is now whiter than white, since 255>>1. When you take a unit-scaled double image and cast it with uint8(), you destroy the image by rounding. The data still spans 0 to 1, but nothing in between. Since 1 is closer to 0 than it is to 255, the image is essentially black.
Unless you are paying attention to what's happening to the data, don't simply cast image data without rescaling accordingly. Tools like im2uint8() and im2double() check the input class and rescale the data accordingly. Use those if you want something safe.
You can choose to adopt whatever class you want for your workflow, but be aware that there are a lot of operations which are not directly compatible with integer-class data, particularly operations images of mixed class.
On the average
I gave an example of a weighted average, which may be useful in some situations. If you only need a simple equal-weighted arithmetic mean, you can simplify the expression easily enough.
You could also use imfuse() if you want, but I never use it.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!