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!