image - MATLAB: layer detection, vector combination and selection by tortuosity/arclength -


i have greyscale image similar 1 below have achieved after post-processing steps (image 0001). vector corresponding bottom of lower bright strip (as depicted in image 0001b). can use im2bw various thresholds achieve vectors in image 0002 (the higher threshold value higher tendency vector line blip upwards, lower threshold higher tendency line blip downwards)..and thinking of going through each vector , measuring arclength on increment (maybe 100 pixels or so) , choosing vector lowest arclength...and adding 100 pixel stretch final vector, creating frankenstein-like vector using straightest segments each of thresholded vectors.. should mention when there multiple straightish/parallel vectors, top 1 best fit.

first off, there better strategy should employing here find line on image 0001? (this needs fast long fitting code wouldn't work). if current frankenstein's monster solution works, suggestions how best go this?

thanks in advance

image=im2bw(image,0.95); %or 0.85, 0.75, 0.65, 0.55 vec=[]; v=1:x     x=1:z         if image(c,v)==1             vec(v)=c;         end     end end vec=fastsmooth(vec,60,20,1); 

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

here modified version of did. works on on images. if want subpixel resolution, can implement active contour model fitting function.

files = dir('*.png'); filenames = {files.name}; ifile=1:length(filenames)     %%     % read image     im0 = double(imread(filenames{ifile}));     %%     % remove background substracting convolution mask     lobj=100;     convmask = ones(lobj,1)/lobj;     im=im0-conv2(im0,convmask,'same');     im(im<0)=0;     imagesc(im);colormap gray;axis image;      %%     % use canny edge filter, alowing extremely weak edge exist     bw=edge(im,'canny',[0.01,0.3]);     % use close operation on image close gaps between lines     % kernel flat rectangular helps connect horizontal     % gaps     se=strel('rectangle',[10,30]);     bw=imdilate(bw,se);     % thin lines single pixel line     bw=bwmorph(bw,'thin',inf);     % connect h bridge     bw=bwmorph(bw,'bridge');     imagesc(bw);colormap gray;axis image;     %% smooth image, find decreasing region, , apply mask     imtmp = imgaussfilt(im0,3);     imtmp = diff(imtmp);     imtmp = [imtmp(1,:);imtmp];     intensity_decrease_mask = imtmp < 0;     bw = bw & intensity_decrease_mask;     imagesc(bw);colormap gray;axis image;      %%     % find properties of lines, , find longest lines     cc=regionprops(bw,'area','pixellist','centroid','majoraxislength','pixelidxlist');     % select lines larger eighth of image width     cc=cc([cc.majoraxislength]>size(bw,2)/8);     %%     % select lines has average intensity larger gray level     i=1:length(cc)         cc(i).meanintensity = mean(im0(sub2ind(size(im0),cc(i).pixellist(:,2), ...         cc(i).pixellist(:,1) )));     end     cc=cc([cc.meanintensity]>150);     cnts=reshape([cc.centroid],2,length(cc))';     %%     % calculate minimum distance bottom right of each edge     i=1:length(cc)         cc(i).distance2bottomright = sqrt(min((cc(i).pixellist(:,2)-size(im,1)).^2 ...             + (cc(i).pixellist(:,1)-size(im,2)).^2));     end     % select bottom edge     [~,minindex]=min([cc.distance2bottomright]);     bottomedge = cc(minindex);     %% clean lines little bit     bwtmp = false(size(bw));     bwtmp(bottomedge.pixelidxlist)=1;     % find end points left , right     endpoints = bwmorph(bwtmp, 'endpoints');     [endy,endx] = find(endpoints);     [~,minind]=min(endx);     [~,maxind]=max(endx);     pos_most_left = [endx(minind),endy(minind)];     pos_most_right = [endx(maxind),endy(maxind)];     % select shortest path between left , right     dists = bwdistgeodesic(bwtmp,pos_most_left(1),pos_most_left(2)) + ...          bwdistgeodesic(bwtmp,pos_most_right(1),pos_most_right(2));     dists(isnan(dists))=inf;     bwtmp = imregionalmin(dists);    bottomedge=regionprops(bwtmp,'pixellist');     %% plot lines     imagesc(im0);colormap gray;axis image;hold on;axis off;     i=1:length(cc)         plot(cc(i).pixellist(:,1),cc(i).pixellist(:,2),'b','linewidth',2);hold on;     end     plot(bottomedge.pixellist(:,1),bottomedge.pixellist(:,2),'r','linewidth',2);hold on;     print(gcf,num2str(ifile),'-djpeg'); %     pause end 

picture 1

picture 2

picture 3

picture 4

picture 5


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -