Contrast equalization with imadjust

17 visualizaciones (últimos 30 días)
David
David el 30 de En. de 2012
Comentada: Image Analyst el 27 de Mayo de 2024
I'm supposed to create a funcion with the following parameters: myEqualization(input_image, method, threshold) Where "method" is a number from 1 to 8 that represent one of these equalizations.
The thing is that I don't understand well how can I manage to do this using imadjust. As fas as I understood from the documentation it correlates a range, to another range. Is that right? Could somebody give me some guidance? Thanks!

Respuesta aceptada

Image Analyst
Image Analyst el 30 de En. de 2012
No, it doesn't do correlations. What is does is to linearly map one intensity region into another. So you could do the first row of your equalization plots because they are linear, but not any on the bottom row because they aren't linear. You could do the ones on the bottom row with intlut().
  2 comentarios
David
David el 30 de En. de 2012
Thanks for the fast answer. Could you please post an example about how to use the "threshold" value together with the imadjust function?
Regarding the second row, I was told that it could be done considering each one as a set of 3 lines, but again no idea how to do it... an example about this would be also greatly appreciated!
Image Analyst
Image Analyst el 27 de Mayo de 2024
Try this:
% Read in low contrast image.
grayImage = imread('pout.tif');
subplot(1, 3, 1);
imshow(grayImage);
title('Original Image')
% Make sigmoid function.
x = 0 : 255;
y = (x - 128) ./ sqrt(128 + (x - 128).^2); %1 ./ (1 + exp(-x));
y = uint8(rescale(y, 0, 255));
subplot(1, 3, 2);
plot(x, y);
title('Look Up Table')
xlabel('Input gray level');
ylabel('Output gray level');
grid on;
% Apply look up table.
outputImage = intlut(grayImage, y);
subplot(1, 3, 3);
imshow(outputImage);
title('Processed Image')

Iniciar sesión para comentar.

Más respuestas (1)

DGM
DGM el 9 de Jul. de 2023
Editada: DGM el 9 de Jul. de 2023
The first four illustrated transformations are very simple -- they're simple addition and multiplication.
% a unit-scale test ramp
x = linspace(0,1,100);
% basic operations
% adjust "brightness" (additive offset)
y1 = x - 0.3; % decrease
y2 = x + 0.3; % increase
hp = plot(x,[y1; y2],'linewidth',2);
legend(hp,{'decrease','increase'},'location','nw');
title('adjust "brightness" (additive offset)')
xlim([0 1]); ylim([0 1])
% adjust "exposure" (multiplicative scaling)
y3 = 0.7*x; % decrease
y4 = x/0.7; % increase
hp = plot(x,[y3; y4],'linewidth',2);
legend(hp,{'decrease','increase'},'location','nw');
title('adjust "exposure" (multiplicative scaling)')
xlim([0 1]); ylim([0 1])
You can do the first four with imadjust() if you really want to, but it's not really convenient to implement these transformations that way.
% IPT imadjust() only does a 2-point linear xform + gamma
% adjust "brightness" (additive offset)
y1 = imadjust(x,[0.3 1],[0 0.7]); % decrease
y2 = imadjust(x,[0 0.7],[0.3 1]); % increase
hp = plot(x,[y1; y2],'linewidth',2);
legend(hp,{'decrease','increase'},'location','nw');
title('adjust "brightness" (additive offset)')
xlim([0 1]); ylim([0 1])
% adjust "exposure" (multiplicative scaling)
y3 = imadjust(x,[0 1],[0 0.7]); % decrease
y4 = imadjust(x,[0 0.7],[0 1]); % increase
hp = plot(x,[y3; y4],'linewidth',2);
legend(hp,{'decrease','increase'},'location','nw');
title('adjust "exposure" (multiplicative scaling)')
xlim([0 1]); ylim([0 1])
What about the other four? Well, imadjust() can't do those. Depending on the specific goals, MIMT imlnc() should be able to handle them all.
% MIMT imlnc() can do all the things
% adjust "brightness" (additive offset)
y1 = imlnc(x,'in',[0.3 1],'out',[0 0.7]); % decrease
y2 = imlnc(x,'in',[0 0.7],'out',[0.3 1]); % increase
hp = plot(x,[y1; y2],'linewidth',2);
legend(hp,{'decrease','increase'},'location','nw');
title('adjust "brightness" (additive offset)')
xlim([0 1]); ylim([0 1])
% adjust "exposure" (multiplicative scaling)
y3 = imlnc(x,'in',[0 1],'out',[0 0.7]); % decrease
y4 = imlnc(x,'in',[0 0.7],'out',[0 1]); % increase
hp = plot(x,[y3; y4],'linewidth',2);
legend(hp,{'decrease','increase'},'location','nw');
title('adjust "exposure" (multiplicative scaling)')
xlim([0 1]); ylim([0 1])
%% adjust contrast using a piecewise power function
y1 = imlnc(x,'k',0.5); % decrease
y2 = imlnc(x,'k',2); % increase
hp = plot(x,[y1; y2],'linewidth',2);
legend(hp,{'decrease','increase'},'location','nw');
title('adjust contrast')
xlim([0 1]); ylim([0 1])
% adjust contrast and gamma
y1 = imlnc(x,'k',2,'g',1.5); % decrease
y2 = imlnc(x,'k',2,'g',0.75); % increase
hp = plot(x,[y1; y2],'linewidth',2);
legend(hp,{'decrease','increase'},'location','nw');
title('adjust contrast and gamma')
xlim([0 1]); ylim([0 1])
What if you want slightly different curves than you can get out of the composition of power functions? Well, MIMT imcurves() will let you use any curve you want.
% do things using MIMT imcurves()
% adjust contrast using an arbitrary curve
xx = linspace(0,1,5);
y1 = imcurves(x,xx,[0 0.35 0.5 0.65 1]); % decrease
y2 = imcurves(x,xx,[0 0.15 0.5 0.85 1]); % increase
hp = plot(x,[y1; y2],'linewidth',2);
legend(hp,{'decrease','increase'},'location','nw');
title('adjust contrast')
xlim([0 1]); ylim([0 1])
% adjust contrast and gamma using an arbitrary curve
xx = linspace(0,1,5);
y1 = imcurves(x,xx,[0 0.1 0.35 0.75 1]); % decrease
y2 = imcurves(x,xx,[0 0.25 0.65 0.9 1]); % increase
hp = plot(x,[y1; y2],'linewidth',2);
legend(hp,{'decrease','increase'},'location','nw');
title('adjust contrast and gamma')
xlim([0 1]); ylim([0 1])
Of course, you can do the same thing using interp1(), but you'll have to pay attention to the class and scale of the image and make sure your control vectors are on the same scale.
y1 = interp1(xx,[0 0.35 0.5 0.65 1],im2double(x),'pchip');
See also:
  1 comentario
DGM
DGM el 27 de Mayo de 2024
Addendum:
A few versions ago, I added a couple extra parameters to imlnc(). There are now three forms of gamma curves available, the properties of which may have particular uses -- but in general, they are a simple way to allow a broader flexibility in selecting which ranges of tones are most affected.
There is the standard power function gamma curve, a reverse curve, and a symmetric curve. Mathematically, these are interrelated. While the symmetric curve is a superelliptic quarter-curve equivalent to a composition of gamma functions, it has been compensated to have a parameter response equivalent to a simple single-pass gamma adjustment. That makes everything simple to use. The standard curve has strongest influence over dark colors; the reverse curve has strongest influence over light colors. The symmetric curve is something in between.
% a unit-scale test ramp
x = linspace(0,1,100);
%% adjust gamma
subplot(1,3,1)
y1 = imlnc(x,'g',2); % gamma > 1
y2 = imlnc(x,'g',0.5); % gamma < 1
hp = plot(x,[y1; y2],'linewidth',2);
legend(hp,{'g > 1','g < 1'},'location','nw');
title('normal gamma curves')
unitaxes(gca)
subplot(1,3,2)
y1 = imlnc(x,'sg',2); % gamma > 1
y2 = imlnc(x,'sg',0.5); % gamma < 1
hp = plot(x,[y1; y2],'linewidth',2);
legend(hp,{'sg > 1','sg < 1'},'location','nw');
title('symmetric gamma curves')
unitaxes(gca)
subplot(1,3,3)
y1 = imlnc(x,'rg',2); % gamma > 1
y2 = imlnc(x,'rg',0.5); % gamma < 1
hp = plot(x,[y1; y2],'linewidth',2);
legend(hp,{'rg > 1','rg < 1'},'location','nw');
title('reverse gamma curves')
unitaxes(gca)
This also allows more flexibility in shaping a contrast curve.
%% adjust contrast and gamma
subplot(1,3,1)
y1 = imlnc(x,'k',2,'g',1.5); % decrease
y2 = imlnc(x,'k',2,'g',0.75); % increase
hp = plot(x,[y1; y2],'linewidth',2);
legend(hp,{'decrease','increase'},'location','nw');
title('adjust contrast and gamma')
unitaxes(gca)
subplot(1,3,2)
y1 = imlnc(x,'k',2,'sg',1.5); % decrease
y2 = imlnc(x,'k',2,'sg',0.75); % increase
hp = plot(x,[y1; y2],'linewidth',2);
legend(hp,{'decrease','increase'},'location','nw');
title('adjust contrast and sgamma')
unitaxes(gca)
subplot(1,3,3)
y1 = imlnc(x,'k',2,'rg',1.5); % decrease
y2 = imlnc(x,'k',2,'rg',0.75); % increase
hp = plot(x,[y1; y2],'linewidth',2);
legend(hp,{'decrease','increase'},'location','nw');
title('adjust contrast and rgamma')
unitaxes(gca)
That allows quite a bit more freedom in creating odd curves before it's necessary to use more cumbersome tools like imcurves()

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by