Removing grids in an image
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposta accettata
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.
Più risposte (1)
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
Image Analyst
il 1 Mag 2015
Modificato: Image Analyst
il 1 Mag 2015
cellsOnlyImage = grayImage > 75;
imshow(cellsOnlyImage);
Vedere anche
Categorie
Scopri di più su Image Processing Toolbox in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!