How can I remove a grid from an image without removing objects on the borders of the grid?
Show older comments
I am writing a program that is going to count red blood cells from an image produced by a transmission microscope. The image is grayscale by default, and the grid in the image has pixel values in the same range as the cells I am trying to count. Here is my code so far (Note: grayscale image corresponds to 'J' in the code)
%Used to isolate cell masks and count the cells on a 4x4 gridded slide
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;
img = imread('fileName');
figure(1)
imshow(img) %show original image from file
[J, rect] = imcrop(img);%User crops photo to control the analyzed area
figure(2)
imshow(J) %show cropped image
impixelinfo;
%%
BW = J < 90 & J > 40;
figure (3)
imshow(BW);
axis on;
title('Binary Image', 'FontSize', fontSize);
%%
cleanBW = bwareaopen(BW, 100, 4);
cleanBW = bwmorph(cleanBW, 'spur');
cleanBW = bwmorph(cleanBW, 'majority', inf);
figure(4)
imshow(cleanBW);
axis on;
I am new to image processing, so I do not know if there should be more filtering on the original grayscale image, or if I would be able to somehow identify the uniform portions (parts without cells) of the grid markings in the binary image and change them from 1s to 0s. All suggestions are welcome!
Accepted Answer
More Answers (2)
GMabilleau
on 28 Jul 2022
0 votes
Image Analyst
on 28 Jul 2022
0 votes
Assuming the grid is in the same position for all images, just use a template to set the grid lines to the mean intensity of the image.
If the grid moves around use radon or hough to find the angle and rotate the image then use the template.
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!