Removing grids in an image
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Image Analyst
2015-4-30
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 个)
Image Analyst
2015-5-1
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 个评论
Image Analyst
2015-5-1
编辑:Image Analyst
2015-5-1
cellsOnlyImage = grayImage > 75;
imshow(cellsOnlyImage);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!