MATLAB: I want to add dot in image

find top edgeImage Processing Toolboxtop hat filter

I have gray image that has array 500×500, after that I want to find maximum value in column for example, I know first column maximum is 254 and position is (1,54) x=1 because first column and y =54 because position in y so I want to add marker(dot) in position (1,54) on this image and do this all column. How to do this? please help me (I want to do like a this image)

Best Answer

A tophat filter with width of about 37 seems good. Did you try that? If not, here is the code:
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;
%===============================================================================
% Read in gray scale demo image.
folder = pwd; % Determine where demo folder is (works with all versions).
baseFileName = '91901.jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% 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(rgbImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
% grayImage = rgb2gray(rgbImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
grayImage = rgbImage(:, :, 2); % Take green channel.
else
grayImage = rgbImage; % It's already gray scale.
end
% Now it's gray scale with range of 0 to 255.
% Display the image.


subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis('on', 'image');
hp = impixelinfo();
%------------------------------------------------------------------------------
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
drawnow;
% Show the histogram
subplot(2, 2, 2);
imhist(grayImage);
grid on;
title('Histogram of Original Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Filter and binarize the image, then find top rows.
% Try it out for different filter window widths.
% Note: A filter window width of 37 or larger seems good for this image.
for windowSize = 31 : 2 : 61
% Do a top hat filter.
edgeImage = imtophat(grayImage, true(windowSize));
% Display the image.
subplot(2, 2, 3);
imshow(edgeImage, []);
caption = sprintf('Top Hat Filter with size %d', windowSize);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
axis('on', 'image');
hp = impixelinfo();
% Binarize the image
binaryImage = imbinarize(edgeImage);
% You could call imfill() to fill it, but it's not really necessary.
% Take just the largest blob, in case there are smaller ones.
binaryImage = bwareafilt(binaryImage, 1);
% Display the image.
subplot(2, 2, 4);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis('on', 'image');
hp = impixelinfo();
% Now go across the columns finding the top row.
topRows = zeros(1, columns);
for col = 1 : columns
row = find(binaryImage(:, col), 1, 'first');
% IF it found something, record it.
if ~isempty(row)
topRows(col) = row;
end
end
% Make missing values the same as the first non-zero column
firstCol = find(topRows, 1, 'first');
topRows(1 : firstCol) = topRows(firstCol);
lastCol = find(topRows, 1, 'last');
topRows(lastCol : end) = topRows(lastCol);
% You could extend the bottom of the binary image to the bottom of the image, but it's not really necessary.
% Plot it over the image
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Image', 'FontSize', fontSize, 'Interpreter', 'None');
hold on;
plot(topRows, 'r-', 'LineWidth', 3);
hold off;
promptMessage = sprintf('Showing filter window size of %d\n\nDo you want to enlarge the window,\nor Accept this size?', windowSize);
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Next', 'Accept and continue', 'Next');
if contains(buttonText, 'Accept', 'IgnoreCase', true)
break;
end
end
% Display top rows in command window
topRows