You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
contrast gain of an image
1 view (last 30 days)
Show older comments
I have an image that from an hazy image model,a haze free image.I need to find the contrast gain of this image.How can I find that,please help me.
Answers (1)
Image Analyst
on 22 Oct 2019
Perhaps look at the ratio of the ranges, or the standard deviations, unless you have a specific formula someone recommends.
15 Comments
Image Analyst
on 22 Oct 2019
Yes, that's what I suggested, and are some metrics. If they work for you, then great!
Image Analyst
on 23 Oct 2019
Try
contrastGain = std(image2(:)) / std(image1(:))
rangeGain = range(image2(:)) / range(image1(:))
Image Analyst
on 29 Oct 2019
How are you defining efficiency? By the length of time it takes???
It should not take that long to compute. How long is it taking for you?
Silpa K
on 30 Oct 2019
Edited: Image Analyst
on 30 Oct 2019
clc
clear
rng default
% Image and parameters
M= imread('img1.tiff');
I=im2double(M);
tot = sum(double(I(:)));
[K L] = size(I);
A=((1./(K*L))*tot);
SD=std2(I);
t1= (I./A);
t2= SD * t1;
t= 1-t2;
Hazy = @(I,A,t) (I-A*(1-t))./t; % Define your function, make sure it is element-wise
J1 = Hazy(I,A,t);
figure,
subplot(1,2,1)
imshow(I,[])
subplot(1,2,2)
imshow(J1,[])
contrastGain = std(J1(:)) / std(I(:));
I am using the above code. I need to find contrast gain of the output image.
Image Analyst
on 30 Oct 2019
How are you defining efficiency? By the length of time it takes???
It should not take that long to compute. How long is it taking for you?
Image Analyst
on 1 Nov 2019
Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 14;
rng default
% Image and parameters
% grayImage = imread('cameraman.tif');
grayImage = imread('pout.tif');
[rows, columns, numberOfColorChannels] = size(grayImage)
startTime = tic;
if numberOfColorChannels > 1
% It's not gray scale, it's color, so convert to gray scale.
grayImage = rgb2gray(grayImage);
end
doubleImage = im2double(grayImage);
tot = sum(double(doubleImage(:)));
% Compute some factors.
A = ((1 ./ (rows*columns)) * tot);
stdDevOriginal = std2(doubleImage);
t1 = doubleImage ./ A;
t2 = stdDevOriginal * t1;
t = 1 - t2;
fprintf('Starting de-hazing process...\n');
% Define your function, make sure it is element-wise
Hazy = @(I, A, t) (I - A * (1 - t)) ./ t;
% Apply the function to the double image.
J1 = Hazy(doubleImage, A, t);
stdDevProcessed = std(J1(:));
contrastGain = stdDevProcessed / stdDevOriginal;
elapsedTime = toc(startTime);
fprintf('Done with de-hazing process.\nIt took %.2f seconds.', elapsedTime);
subplot(2, 2, 1)
imshow(doubleImage)
caption = sprintf('Original image. StdDev = %.3f', stdDevOriginal);
title(caption, 'FontSize', fontSize);
axis('on', 'image');
impixelinfo;
subplot(2, 2, 2)
imshow(J1)
caption = sprintf('Processed Image. StDev = %.3f\n with contrast gain %.2f', ...
stdDevProcessed, contrastGain);
title(caption, 'FontSize', fontSize);
axis('on', 'image');
impixelinfo;
subplot(2, 2, 3)
imshow(t)
title('The "t" image', 'FontSize', fontSize);
axis('on', 'image');
impixelinfo;
%------------------------------------------------------------------------------
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
message = sprintf('Done!\nThe elapsed time was %.3f seconds.', elapsedTime);
fprintf('%s\n', message);
uiwait(helpdlg(message));
How gigantic is your image? For my demo image, I see
rows =
291
columns =
240
numberOfColorChannels =
1
Starting de-hazing process...
Done with de-hazing process.
It took 0.01 seconds.Done!
The elapsed time was 0.011 seconds.
Note that it took only a hundredth of a second, not 5 minutes. Also note that the haze removal is not that good. You might want to investigate your algorithm further (I did not do that - I just took the formula you gave).
Image Analyst
on 3 Nov 2019
Yes, if the image became less contrasty, like if the processed image was a completely uniform gray level.
Image Analyst
on 4 Nov 2019
Like this:
grayImage = 128 * ones(480, 640, 'uint8');
That makes an image with 480 rows and 640 columns with a uniform gray level of 128.
See Also
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)