- Find edges in the image using edge function
- Apply hough transform on the edges
- Calculate the peaks of hough transform using houghpeaks
- Extract the line coordinates using houghlines
Calculate mean distance between lines in an image
6 次查看(过去 30 天)
显示 更早的评论
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);
figure(3);
imshow(im2);
%% ImFindCircles
rmin = 3;
rmax = 11;
sensitivity = 0.9;
[centers,radii] = imfindcircles(im2, [rmin rmax], 'Sensitivity',sensitivity, 'Method','TwoStage');
figure(2)
imshow(im, [])
viscircles(centers,radii);
%% Region Properties
props = regionprops(im2,'all');
allCircularities = [props.Circularity];
allAreas = [props.Area];
sigAreas = find(allAreas > 100);
cellAreas = allAreas(sigAreas);
figure(4);
imshow(im, []);
centroids1 = cat(1,props.Centroid);
hold on;
plot(centroids1(:,1),centroids1(:,2),'b*');
hold off;
%% Overlay Mask
figure(5);
hold on;
colormap([0 0 1; 1 1 1]);
colouredimage = label2rgb(im2 + 1, colormap);
C = imfuse(im,colouredimage,'blend');
imshow(C);
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!
0 个评论
回答(1 个)
Rohit Pappu
2021-3-24
For extracting the straight lines, a plausible solution is as follows
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Segmentation and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!