Clear Filters
Clear Filters

Calculate mean distance between lines in an image

1 view (last 30 days)
I am currently working on a project to compare cell features in different conditions - one of which is size.
I've attached two examples of the images I am working with - as is apparent, the scale of the image varies quite substantially.
So far, I have done some work segmenting the image to calculate various cell properties: this is about 90% effective at finding the cells.
clearvars; close all;
%% Read Image
im = double(imread('testimage.bmp'));
%% Segment
[~,threshold] = edge(im,'sobel'); %Calculate sobel threshold
fudgefactor = 0.5; %Reduce by a factor
im2 = edge(im,'sobel',threshold * fudgefactor);
se90 = strel('line',2,90); %structuring
se0 = strel('line',2,0);
im2 = imdilate(im2, [se90 se0]); %Dilate image
im2 = imclearborder(im2,4);
im2 = imfill(im2,'holes');
erosion = strel('diamond',1); %Erode image twice
im2 = imerode(im2,erosion);
%% ImFindCircles
rmin = 3;
rmax = 11;
sensitivity = 0.9;
[centers,radii] = imfindcircles(im2, [rmin rmax], 'Sensitivity',sensitivity, 'Method','TwoStage');
imshow(im, [])
%% Region Properties
props = regionprops(im2,'all');
allCircularities = [props.Circularity];
allAreas = [props.Area];
sigAreas = find(allAreas > 100);
cellAreas = allAreas(sigAreas);
imshow(im, []);
centroids1 = cat(1,props.Centroid);
hold on;
hold off;
%% Overlay Mask
hold on;
colormap([0 0 1; 1 1 1]);
colouredimage = label2rgb(im2 + 1, colormap);
C = imfuse(im,colouredimage,'blend');
hold off;
If anyone spots anything obvious where I could refine that to detect the remainder of the cells (try running it with testimage3), I am open to input, but the next hurdle I'm not quite sure how to approach is to focus on the lines in the images instead.
The distance between the main lines is 0.25mm. I figure the steps are to a) Threshold the image so as to only have the gridlines visible b) Approximate them as straight lines c) calculate the number of pixels between those lines such that the diameters and areas can be to scale.
Precision is important but a systematic error is acceptable since I have 1000 or so images, and I am comparing them to each other rather than looking at images in isolation.
Does anyone have any ideas as to how i might do this?
Thanks as always!

Answers (1)

Rohit Pappu
Rohit Pappu on 24 Mar 2021
For extracting the straight lines, a plausible solution is as follows
For further reference, please check this example out




Community Treasure Hunt

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

Start Hunting!