フィルターのクリア

Unsharp mask amplification - limiting local contrast

6 ビュー (過去 30 日間)
Jonathan
Jonathan 2024 年 9 月 23 日
編集済み: DGM 2024 年 9 月 24 日

I have a script that produces unsharp masks from an input image (in this example, a solar eclipse image):

im = im2double(imread("image.tif"));
imb = imgaussfilt(im, 8);
hp = im - imb; 

To amplify the effects of this high pass filter, I multiply it by a constant:

amp = 100;
hpamp = amp * hp;
subplot(2,1,1), imshow(hp+0.5,[0,1])
subplot(2,1,2), imshow(hpamp+0.5,[0,1])

As expected, the dark areas got darker and the bright areas got brighter, but at a certain amplification value, this will over darken and brighten the sharpened image (as indicated in the attached image). I've tried a few ways (masking, etc) of limiting the amplification locally, but with no success (that looks acceptable). I'd like the amplification to be applied non-linearly throughout the image.

Does anyone know of a method that I could use to amplify the effects of the unsharp mask while correcting for the local contrast (if it's even possible)? If I'm going about this all wrong, please feel free to provide other feedback as well.

回答 (1 件)

DGM
DGM 2024 年 9 月 24 日
編集済み: DGM 2024 年 9 月 24 日
I'm not sure I know what the goals are here, but I'll go.
Instead of increasing global contrast, try a piecewise approach.
% cropped from a low-quality JPG screenshot
inpict = imread('IMG_2294.jpeg');
inpict = im2gray(inpict);
% curve parameters
hw = 0.1; % half-width of central portion (0 <= hw <= 0.5)
kc = 1.5; % slope in central region (kc >= 1)
kt = 2; % slope of tails (kt >= kc)
% construct the curve
pax = 0.5 + hw;
pay = 0.5 + kc*hw;
pbx = 0.5 - hw;
pby = 0.5 - kc*hw;
C = [0 0; (pbx - pby/kt) 0; pbx pby; pax pay; (pax + pby/kt) 1; 1 1];
% plot the curve
plot(C(:,1),C(:,2))
unitaxes()
% apply the curve to the image
outpict = im2double(inpict);
outpict = interp1(C(:,1),C(:,2),outpict,'linear','extrap');
outpict = min(max(outpict,0),1);
% compare the results
montage({inpict outpict})
With this example, the contrast near the central pivot can be controlled independently of the contrast in light and dark regions. In this case, I only applied a slight boost near gray, but a much stronger boost on the tails. Compare the tail positions of the contrast curve with the distribution of values on the input.
% look at the input distribution
imhist(im2double(inpict))
The result is minimal clipping, though that amount can be adjusted with the curve parameters.

製品


リリース

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by