Removing grids in an image

6 visualizzazioni (ultimi 30 giorni)
hu
hu il 30 Apr 2015
Modificato: Image Analyst il 1 Mag 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

Risposta accettata

Image Analyst
Image Analyst il 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 Commento
hu
hu il 30 Apr 2015
Modificato: hu il 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?

Accedi per commentare.

Più risposte (1)

Image Analyst
Image Analyst il 1 Mag 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 Commenti
hu
hu il 1 Mag 2015
Modificato: hu il 1 Mag 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 il 1 Mag 2015
Modificato: Image Analyst il 1 Mag 2015
cellsOnlyImage = grayImage > 75;
imshow(cellsOnlyImage);

Accedi per commentare.

Categorie

Scopri di più su Image Processing Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by