Calculate mean distance between lines in an image
5 views (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'));
[~,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);
rmin = 3;
rmax = 11;
sensitivity = 0.9;
[centers,radii] = imfindcircles(im2, [rmin rmax], 'Sensitivity',sensitivity, 'Method','TwoStage');
%% Region Properties
props = regionprops(im2,'all');
allCircularities = [props.Circularity];
allAreas = [props.Area];
sigAreas = find(allAreas > 100);
cellAreas = allAreas(sigAreas);
centroids1 = cat(1,props.Centroid);
%% Overlay Mask
colormap([0 0 1; 1 1 1]);
colouredimage = label2rgb(im2 + 1, colormap);
C = imfuse(im,colouredimage,'blend');
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!