how to get the same contrast in an image?

3 views (last 30 days)
Valeria Leto
Valeria Leto on 17 Oct 2021
Answered: Image Analyst on 12 Nov 2021
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
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
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.

Sign in to comment.

Answers (2)

yanqi liu
yanqi liu on 1 Nov 2021
sir,may be use the hist vector, such as
J = histeq(I,hgram)
  1 Comment
Abhishek Kolla
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

Sign in to comment.


Image Analyst
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;

Community Treasure Hunt

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

Start Hunting!