1
$\begingroup$

I want to remove a bright spot in an image. This is the image I used:

this is image i used

and this is the Matlab code I wrote:

clc;                 % Clear the command window.
close all;           % Close all figures (except those of imtool.)
imtool close all;    % Close all imtool figures if you have the Image Processing Toolbox.
clear;               % Erase all existing variables. Or clearvars if you want.
workspace;           % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 18;

%==================================================================
% Read in a color demo image.
folder = 'C:\wamp64\www\EE368_Android_Tutorial3_Server\Stadium 3 Cropping';
baseFileName = '003.png';

% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);

if ~exist(fullFileName, 'file')
    % Didn't find it there.  Check the search path for it.
    fullFileName = baseFileName;         % No path this time.

    if ~exist(fullFileName, 'file')
        % Still didn't find it.  Alert user.
        errorMessage = sprintf('Error: %s does not exist.', fullFileName);
        uiwait(warndlg(errorMessage));
        return;
    end
end


rgbImage = imread(fullFileName);
% Get the dimensions of the image.  numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(rgbImage);

% Display the original color image.
subplot(2, 3, 1);
imshow(rgbImage);
axis on;
title('Ori  ginal Color Image', 'FontSize', fontSize);

% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);

% Convert to gray scale.
grayImage = rgb2gray(rgbImage);
subplot(2, 3, 2);
imshow(grayImage);
axis on;
title('Gray scale Image', 'FontSize', fontSize);

% Let's compute and display the histogram.
[pixelCount, grayLevels] = imhist(grayImage);
subplot(2, 3, 3); 
bar(grayLevels, pixelCount);
grid on;
title('Histogram of gray image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.

% Threshold to get binary image
binaryImage = grayImage > 225;
subplot(2, 3, 4);
imshow(binaryImage);
axis on;
title('Binary Image', 'FontSize', fontSize);

% Dilate the binary image to tell it what pixels shoudl be used to fill in holes.


binaryImage = imdilate(binaryImage, true(17));

subplot(2, 3, 5);
imshow(binaryImage);
axis on;
title('Dilated Binary Image', 'FontSize', fontSize);
drawnow;


promptMessage = sprintf('Next we will fill the white areas.\nNote: Computing the filled image will take some time.');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')
    return;
end
tic

% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);

% Fill holes
redChannel = regionfill(redChannel, binaryImage);
greenChannel = regionfill(greenChannel, binaryImage);
blueChannel = regionfill(blueChannel, binaryImage);

% Recombine separate color channels into a single, true color RGB image.
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
subplot(2, 3, 6);
imshow(rgbImage);
axis on;
title('Fixed Color Image', 'FontSize', fontSize);
gray = rgb2gray(rgbImage);
offsets = [0 1;-1 1;-1 0;-1 -1];
[GLCMS,SI] = graycomatrix(gray,'Of',offsets); 
stats = graycoprops(GLCMS,{'contrast','homogeneity','correlation','energy'});

toc;

The result is the following.

enter image description here

Maybe someone can help me to fix this. Thanks in advance.

$\endgroup$
  • $\begingroup$ there is remove and then there is knocking the intensity down so that it doesn’t obscure the rest of the image, using histeq or a variant $\endgroup$ – Stanley Pawlukiewicz Oct 28 '17 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.