Changing contrast of the image

9 visualizzazioni (ultimi 30 giorni)
aaaa Vadimov
aaaa Vadimov il 21 Lug 2011
Modificato: DGM il 6 Lug 2022
Hi,
I try to decrease the contrast to 50% and I am using imadjust function. I tried:
imadjust(originalImage, [0.5 1], [0 1]);
and
imadjust(originalImage, [0 0.5], [0 1]);
They both do not give the result I have in the photoshop (-50% on contrast slider).
I can remove the white background or not in photoshop, but the result is still different.
Any idea how I solve it? I need it to look like in the photoshop...
Thanks,
Vadim

Risposte (1)

DGM
DGM il 6 Lug 2022
To preface, I have no idea how PS actually calculates anything internally, and I don't have the original image, so this is not necessarily exactly the same. I don't think those details matter anymore.
For a basic demonstration of brightness/contrast controls, see this post. The methods described therein are implemented in MIMT imbcg(). While imbcg() is simple in that it replicates the usage found in common image editing software, you can do the same thing with imadjust(). Imadjust() is more akin to a 'Levels' type adjustment tool, but it can be used to effect linear 'brightness/contrast' controls with some effort and insight. While moving the input levels toward center will raise contrast, moving output levels toward center will decrease contrast.
A = imread('cameraman.tif');
contrastamt = -0.5; % -50% contrast
olhi = tan((contrastamt+1)*pi/4)*0.5 + 0.5; % 1/sqrt(2) for -50%
B = imadjust(A,[0 1],[1-olhi olhi],1);
% the same can be done more succinctly with third-party tools
%B = imbcg(A,'c',contrastamt);
imshow([A B])
Note the calculation of the output limit. Compare this to the calculations described in the linked demo.

Community Treasure Hunt

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

Start Hunting!

Translated by