how to get the same contrast in an image?
Show older comments
Hi! I have image o.png which shows a difference in the contrast of the pixels, there is like a "line" that divide two different parts. I tried with histeq but I don't get any results. Any suggestions? Thank you
9 Comments
Abhishek Kolla
on 1 Nov 2021
The contrast can be adjusted using Image viewer App in MATLAB. The step by step procedure can be found here Adjust Image Contrast in Image Viewer App - MATLAB & Simulink (mathworks.com)
Valeria Leto
on 1 Nov 2021
Abhishek Kolla
on 2 Nov 2021
The values low_in and high_in refer to the intensity values in the input image which you want to map to low_out and high_out in the transformed output image. In the example intensites with value 0.3 in old image will be mapped to be 0.2 and similarly 0.5 will be mapped to 0.9 in the transformed image
Valeria Leto
on 2 Nov 2021
Abhishek Kolla
on 3 Nov 2021
When the intensities which we want to vary are known beforehand we can use imadjust function. Otherwise image viewer app can be used
Valeria Leto
on 8 Nov 2021
Valeria Leto
on 8 Nov 2021
Abhishek Kolla
on 12 Nov 2021
The step by step process to save and export the final modified image can be found here Get Started with Image Viewer App - MATLAB & Simulink (mathworks.com)
Image Analyst
on 12 Nov 2021
Taking the histogram or increasing contrast with histogram equalization or imadjust() will not help you with finding the line. Just think about it.
I'd try thresholding and then do some cleanup with bwareafilt() and sgolayfilt(). I'll give code later today if I have time.
Answers (2)
yanqi liu
on 1 Nov 2021
0 votes
sir,may be use the hist vector, such as
J = histeq(I,hgram)
1 Comment
Abhishek Kolla
on 1 Nov 2021
In the above function hgram refers to target histogram. We can use it when the histogram of output image has to approximately match target histogram hgram
Image Analyst
on 12 Nov 2021
To find the left edge of that bright strip, try this:
% Demo by Image Analyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
markerSize = 40;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
fileName = 'o.PNG';
grayImage = imread(fileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Extract the blue channel (so the magenta lines will be white).
grayImage = grayImage(:, :, 3);
end
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(2, 2, 1);
imshow(grayImage, []);
impixelinfo;
axis('on', 'image');
title('Original Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
hold on
drawnow;
% Maximize window.
g = gcf;
g.WindowState = 'maximized'
drawnow;
% Get rid of white frame.
frame = grayImage == 240;
grayImage(frame) = 0;
subplot(2, 2, 2);
imhist(grayImage);
grid on;
low = 104;
high = 255;
% [low, high] = threshold(low, high, grayImage)
mask = grayImage > low;
% Take biggest blob
mask = bwareafilt(mask, 1);
% Fill holes.
mask = imfill(mask, 'holes')
% Display the image.
subplot(2, 2, 3);
imshow(mask, []);
impixelinfo;
axis('on', 'image');
title('Mask Image', 'FontSize', fontSize, 'Interpreter', 'None');
hold on
drawnow;
% Scan down getting left edge of bright strip.
leftEdges = nan(rows, 1);
hold on;
for row = 1 : rows
t = find(mask(row, :), 1, 'first');
if ~isempty(t)
leftEdges(row) = t;
plot(t, row, 'r.', 'MarkerSize', 8);
end
end
subplot(2, 2, 4);
plot(leftEdges, 'b-', 'LineWidth', 2);
grid on;
title('Left Edges', 'FontSize', fontSize, 'Interpreter', 'None');
xlabel('Row', 'FontSize', fontSize, 'Interpreter', 'None');
ylabel('Column of left edge', 'FontSize', fontSize, 'Interpreter', 'None');
hold on
drawnow;

Categories
Find more on Contrast Adjustment in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!