optimization of scobel image processing - better approach needed
Afficher commentaires plus anciens
Hello,
i have pictures with bands. The bands can be tilted. There can be 1 upto 5 bands on a image. I need the width of atleast one band!
My script just work for 50% of the images and almost always i need some manual adjustments for different types of the pattern. Im looking for a generalized solution without manual adjustments.
Thank You.
My Code:
%% User variable
image_name = '1';
image_extension = '.png';
% two lines will be detected at top and bottom of the imagee. That is why
% you will see +/- 2 in the script below at number of places. if band is not
% detected fully this number can be increased.
number_of_lines = 10;
% possible value (0.1 - 0.5) This should be increased if band is present in lighter region.
intensity_factor = 0.1;
% This is filter to segment the line. If line is bolder then 2 in (2,20) should be
% increased to appropriate value. for these images, 2 is fine.
% if there are more feature in the band boundary then 20 in (2,20) can be
% adjusted.
line_filter = [ones(2,20);zeros(2,20);-ones(2,20)] ;
%% Line detection
im1 = imread([image_name image_extension]) ;
im2 = (im2double(rgb2gray(im1)));
imProcess = adapthisteq(im2);
fimg = imfilter((imProcess),line_filter );
bw = edge(fimg,'sobel');
[H,T,R] = hough(bw);
P = houghpeaks(H,number_of_lines+2,'threshold',ceil(intensity_factor*max(H(:))));
lines = houghlines(fimg,T,R,P,'FillGap',10,'MinLength',100);
f_1 = figure(1);
clf
imshow(im1), hold on
mid_point = zeros(length(lines)-2,2) ;
for k = 1:length(lines)-2
xy = [lines(k+2).point1; lines(k+2).point2];
mid_point(k,:) = mean(xy) ;
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
end
%% Bandwidth calculation
dist_points = triu(pdist2(mid_point,mid_point)) ;
dist_points(dist_points==0) = nan;
bandwidth = min(dist_points,[],'all') ;
[row,col] = find(dist_points==bandwidth);
plot(mid_point([row(1) col(1)],1),mid_point([row(1) col(1)],2),'LineWidth',2,'Color','red') ;
title(['Band Width = ', num2str(bandwidth), ' pixels'])
drawnow
%% File save
save([image_name,'.mat'],'bandwidth')
print(f_1,'-dpng',[image_name,'_line'])
Réponse acceptée
Plus de réponses (1)
Image Analyst
le 16 Fév 2021
0 votes
What happens if you try stdfilt(), or look at the vertical profile by summing the image horizontally?
1 commentaire
Image Analyst
le 16 Fév 2021
What are these things? What do you really want to know?
- A line fitted along the top and bottom of each "band"?
- The angle of that band?
- The average width of the band (why would it vary)?
- Do you want the outline to be not a line but "hug" the regions somewhat closely (how closely)?
- The width of each band as a function of column in the image?
- The width of each band perpendicular to the main axis of each band?
- Have you tried activecontour() or Chan-Vese segmentation?
- Have you tried SegNet (segmentation deep learning)?
Catégories
En savoir plus sur Explore and Edit Images with Image Viewer App dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
