contrast gain of an image
2 次查看(过去 30 天)
显示 更早的评论
Silpa K
2019-10-22
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.
回答(1 个)
Image Analyst
2019-10-22
Perhaps look at the ratio of the ranges, or the standard deviations, unless you have a specific formula someone recommends.
15 个评论
Silpa K
2019-10-22
There is no recommended specific formula for this. Is there any function available for this.
Is it possible to find contrast gain using ratio of the ranges, or the standard deviations.
Image Analyst
2019-10-22
Yes, that's what I suggested, and are some metrics. If they work for you, then great!
Image Analyst
2019-10-23
Try
contrastGain = std(image2(:)) / std(image1(:))
rangeGain = range(image2(:)) / range(image1(:))
Silpa K
2019-10-29
Sir, I tried this one,I am not getting efficient result.Is there is any other methods for finding contrast gain.
Image Analyst
2019-10-29
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
2019-10-30
编辑:Image Analyst
2019-10-30
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
2019-10-30
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
2019-11-1
Sir,we are expecting a value that is less than one. For computing it not taking more amount of time only less than 4 or 5 minutes.
Image Analyst
2019-11-1
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));
![0001 Screenshot.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/246067/0001%20Screenshot.png)
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
2019-11-3
Yes, if the image became less contrasty, like if the processed image was a completely uniform gray level.
Silpa K
2019-11-4
How can I do that? What is the method to get a image completely uniform gray level.
Image Analyst
2019-11-4
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.
Silpa K
2019-11-5
How can I apply it into the output image.I need a output image that is fully uniform gray level,bcz I need a output image with less contrast.
另请参阅
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)