how to detect the haziness of the color image?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
i need to find the haziness in the color image
0 commentaires
Réponses (2)
Gautam
le 23 Oct 2024 à 11:59
One of the simple ways to determine haziness of an image is to analyze the contrast and clarity of the image. Hazy images often have reduced contrast and a lack of sharp edges.
Here is an example demonstrating how to do this:
% Read the image
img = imread('peppers.png'); % Replace with your image file
grayImg = rgb2gray(img);
% Compute edge information using the Sobel operator
edges = edge(grayImg, 'Sobel');
% Calculate the edge density (percentage of edge pixels)
edgeDensity = sum(edges(:)) / numel(edges);
% Compute the contrast of the grayscale image
contrast = std(double(grayImg(:))) / mean(double(grayImg(:)));
% Estimate haziness (lower edge density and contrast suggest higher haziness)
hazinessScore = 1 - (edgeDensity + contrast) / 2;
% Display the results
fprintf('Edge Density: %.4f\n', edgeDensity);
fprintf('Contrast: %.4f\n', contrast);
fprintf('Haziness Score: %.4f\n', hazinessScore);
0 commentaires
DGM
le 25 Oct 2024 à 23:31
Modifié(e) : DGM
le 26 Oct 2024 à 4:05
I wasn't going to post this, but I guess I will anyway.
I went and grabbed a paper on a "haziness" metric.
... and I reimplemented the proposed (and most of the reference contrast metrics) in MATLAB. Some of the code does depend on MIMT, though I did make some effort to make sure everything would all run in a period-correct version (R2015b).
The individual demos are sections within haziness_ws.m, one of which is replicated here:
%% contrast vs medium density (RGB channelwise metrics)
density = [0 5 10 15 20 25 30 35];
F = {@(x) haziness_vitor(x);
@(x) haziness_gautam(x);
@(x) contrast_hs(x);
@(x) contrast_rms(x);
@(x) contrast_michelson(x)};
titles = {'Vitor','Gautam','Histogram Spread','RMS','Michelson'};
% calculate everything
nf = numel(F);
nd = numel(density);
K = zeros(nd,3,numel(F));
for k = 1:nd
% the included images come from the original author (see links)
fname = sprintf('recorte_leite_%02d.jpg',density(k));
inpict = imread(fname);
for p = 1:nf
K(k,:,p) = F{p}(inpict);
end
end
% plot everything
CT = [1 0 0; 0 1 0; 0 0 1];
for p = 1:nf
subplot(3,2,p+1)
colororder(CT);
plot(density,K(:,:,p))
title(titles{p})
xlabel('contaminant amount (mL)')
xlim(imrange(density))
end
subplot(3,2,1)
inpict = imread('recorte_leite_00.jpg');
imshow(rot90(inpict))
title('base image')
I included @Gautam's proposed method as well, though I inverted it as a reluctant compromise. Since all the other metrics were treated as "contrast" rather than "haziness", I felt the comparison was easier if they all had the same general behavior. By themselves, I would think that a "haziness" metric would follow Gautam's intended behavior. That's especially true for something like Vitor, which is ostensibly a proxy for the physical medium density (as opposed to the perceptual aspects).
This answer isn't a recommendation for any particular method. I just grabbed the first clear paper and ran with it. There are countless papers on contrast metrics, and I'm sure there are plenty specifically on measures of haze. If this one isn't what you want, pick another.
I don't have academic access anymore, and in the last 15 years, I've wasted way too many hours trying to implement crap in papers only to figure out that there are gross errors in the equations or entire chunks of the process which were left completely undescribed. Like I said, first clear paper. I'm not going to keep digging.
EDIT: FWIW, I thought I had posted a technique similar to Gautam's, but I don't see it. It might have been an unused demo for docs. Regarding MIMT imstats() has an 'edginess' metric that's derived from the gradient estimate without the effects of binarization and thinning. It also has a rough local contrast metric, but you can do the mean-normalized standard deviation too.
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% this isn't really necessary
% i just wanted to shove MIMT crap into the workflow
function K = haziness_gautam_dgm(inpict)
% get some things from imstats()
% this handles multichannel images, excludes NaNs
% and returns unit-scale statistics regardless of input class
stats = imstats(inpict,'edginess','std','mean','normalized');
% Estimate haziness (lower edge density and contrast suggest higher haziness)
K = [stats(1,:); stats(2,:)./stats(3,:)];
K = mean(K,1);
end
The result is very similar to the included haziness_gautam(). There's no huge benefit to doing it this way, though it might be easier to write if you're used to it. The one thing imstats() does is that it will automagically return stats for all channels. It also does a bunch to safeguard against letting NaNs ruin the summary statistics.
0 commentaires
Voir également
Catégories
En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!