Automatic Image Level Adjustment

21 次查看(过去 30 天)
Matej Znidaric
Matej Znidaric 2020-5-20
回答: DGM 2022-7-6
Hi everyone!
I would be really thankful if you could solve the following problem. I've transformed image from RGB to cieLAB and then extracted a channel. How can I automatically adjust the tonal range of the a channel like in Adobe Photoshop?
A = imread('image.jpg');
CT = makecform('srgb2lab');
lab = applycform(A,CT);
a = lab(:,:,2);
%????? --> how to automatically adjust the tonal range of a channel?

回答(1 个)

DGM
DGM 2022-7-6
A simple linear "Levels" type adjustment tool is exactly what imadjust() provides. In the Photoshop UI, you have five parameters controlled by five sliders:
  • input levels (low and high)
  • gamma (the center handle)
  • output levels (low and high)
IPT imadjust() allows you to explicitly specify input and output levels along with gamma.
% a test image
A = imread('pout.tif');
% show the image and its histogram
subplot(1,2,1); imshow(A);
subplot(1,2,2); imhist(A);
The levels can be explicitly set:
% manually adjust the image (input levels)
B = imadjust(A,[0.2 0.8]);
% show the image and its histogram
figure
subplot(1,2,1); imshow(B);
subplot(1,2,2); imhist(B);
... or the levels can be automatically determined by using stretchlim() and feeding the result to imadjust(). The tolerance used by stretchlim() can be optionally specified if desired.
% automatically adjust the image (input levels)
inrange = stretchlim(A,0.005) % saturate 1% of pixels (default is 2%)
inrange = 2×1
0.3020 0.6863
C = imadjust(A,inrange);
% show the image and its histogram
figure
subplot(1,2,1); imshow(C);
subplot(1,2,2); imhist(C);
For grayscale images like the above, it's not strictly necessary to call stretchlim() directly, unless it's desired to use a non-default tolerance. The short syntax for imadjust() will internally call stretchlim() (with the default 2% tolerance).
% automatically adjust the image (input levels)
D = imadjust(A); % this syntax only works on single-channel images
% show the image and its histogram
figure
subplot(1,2,1); imshow(D);
subplot(1,2,2); imhist(D);

类别

Help CenterFile Exchange 中查找有关 Get Started with Image Processing Toolbox 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by