Removing grids in an image

6 views (last 30 days)
hu
hu on 30 Apr 2015
Edited: Image Analyst on 1 May 2015
Dear all,
Following the image attached, is there a way to create a new image that only show the cells (omitting the white grid lines)?
Thanks

Accepted Answer

Image Analyst
Image Analyst on 30 Apr 2015
Sure. It's pretty easy. Just look at how I get rid of salt and pepper noise in the attached demo. Basically you identify bright pixels by thresholding. Then you take the median filter of the image. Then, where there are bright pixels, you replace them with the values from the median filtered image. Pretty trivial but let me know if you run into trouble.
  1 Comment
hu
hu on 30 Apr 2015
Edited: hu on 30 Apr 2015
Thanks, I understand that I need to use the medfilt2(A) but how do I know what is the matrix?
How do I identify bright pixels by thresholding?

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 1 May 2015
Try this:
clc; % Clear command window.
clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
imtool close all; % Close all figure windows created by imtool.
workspace; % Make sure the workspace panel is showing.
fontSize = 15;
% Read in a standard MATLAB demo image.
folder = pwd;
baseFileName = 'grid.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
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
% Display the original image.
subplot(2, 2, 1);
imshow(grayImage);
axis on;
title('Original Gray Scale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
% Let's compute and display the histogram.
[pixelCount, grayLevels] = imhist(grayImage);
subplot(2, 2, 2);
bar(grayLevels, pixelCount);
grid on;
title('Histogram of original image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
% Median Filter the image:
medianFilteredImage = medfilt2(grayImage, [23 23]);
% Find the noise. It will have a gray level of either 0 or 255.
noiseImage = grayImage > 125;
% Display the image.
subplot(2, 2, 3);
imshow(noiseImage);
axis on;
title('Noise', 'FontSize', fontSize);
% Get rid of the noise by replacing with median.
noiseFreeImage = grayImage; % Initialize
noiseFreeImage(noiseImage) = medianFilteredImage(noiseImage); % Replace.
% Display the image.
subplot(2, 2, 4);
imshow(noiseFreeImage);
axis on;
title('Restored Image', 'FontSize', fontSize);
It doesn't get the really big white lines. You'd need to do a second pass with a bigger median window, or else just use meshgrid() and interp2() instead of medfilt2().
  2 Comments
hu
hu on 1 May 2015
Edited: hu on 1 May 2015
Thanks a lot it works well. Is there a way just to show the cells in a new figure (cells in black, background in white)?
Image Analyst
Image Analyst on 1 May 2015
Edited: Image Analyst on 1 May 2015
cellsOnlyImage = grayImage > 75;
imshow(cellsOnlyImage);

Sign in to comment.

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!