Prev: Find word in string
Next: starn matlab with crontab
From: Lars-Göran Nord on 3 Aug 2010 16:08 "Sean " <sean.dewolski(a)nospamplease.umit.maine.edu> wrote in message <i39kh5$fbv$1(a)fred.mathworks.com>... > "Lars-Göran Nord" <lars-goran.nordh(a)uddeholm.se> wrote in message > > Thank you Sean, > > > > I will look deeper into this this evening, as I'm not an expert in this it takes some time for me to figure it all out:-) > > Do you think I can solve all this with some help:-) I have to tell my boss this monday if its possible or not. Othervise they will outsorce the whole thing, and I really dont like that at all. And the pleasure of success is aalso very sweet:-) > > > > Thanks again, > > Lars > > You're welcome! > > It's definitely doable and I think you're close to the solution. The programming aspects of this shouldn't be too hard as you have the aid of the Image Processing Toolbox. > > Global approach: > -Create the skeleton with the aid of Image Analyst's example > -Calculate the orientation at each point on the skeleton using the bwconncomp, regionprops functions. > -To get length across pixel use the approach I gave you from above (total line length). > -To get max crack width: at each skeleton point calculate the angle orthogonal to that point's orientation. Using this orientation figure out how many point lie along a line drawn at this angle. Use the cos()^-1 formula to get this width too. The only time this would falter would be at intersections. > > %%% > %Here is the code to do the first 3 steps in one shot. I think you'll like the results! > %%% > % > %SCd 08/03/2010 > %% Load and Binarize > I = imread('/Users/Userx/Downloads/cr1.tif'); > I = I(:,:,1) < 52; %Binarize > I = padarray(I,[2 2],false,'both'); %Pad the array for later use > %% ImageAnalyst's Skeleton > > skel = bwmorph(I, 'skel',inf); > % Display the skeletonized image. > imtool(skel); > > % Calculate total crask > binaryArea = sum(I(:)); > > % Calculate the length of all the cracks. > skelArea = sum(skel(:)); > > % Divide the area by the length to get the average width. > mean_crackWidth1 = binaryArea / skelArea > > %% Get Orientation at each point > > my_orientations = zeros(size(I)); %Preallocate > [r c] = find(skel); %[row col] indices of points on skel > %Note: This is why we padded earlier: > % all r,c are greater>=3 and <= size(dim) -2 > > %Go to each point and calculate orientation > for ii = 1:length(r) > %Extract all pixels within the 5x5 window surrounding our point > SKpart = skel((r(ii)-2):(r(ii)+2),(c(ii)-2):(c(ii)+2)); > > %Connected components analysis, 8 connectivity (we care about corners!) > CC =bwconncomp(SKpart,8); > > %Get orientation. > RP = regionprops(CC,'Orientation'); > > %Save the orientation. This may need modified if there are multiple > %Orientations returned in the even of more than one object > my_orientations(r(ii),c(ii)) = RP.Orientation; > end > > %Sign doesn't matter > length_orientations = abs(my_orientations); > > %Get angle closest to any axis > length_orientations(length_orientations>45) = 90 - length_orientations(length_orientations>45); > > %Get length, preserving only those in the skeleton > eachLength = 1./cosd(length_orientations).*double(skel); > skelLength = sum(eachLength(:)); > > %Crack area divided by length > mean_crackWidth2 = binaryArea/skelLength > > %Compare to Image Analyst's: > mean_crackWidth1/mean_crackWidth2 Sean, This looks fantastic, fighting with my old car right now 1966 Impala conv. but will check later. Don't know how to thank you......... I'm very happy. Be back later. Thank you so much Sean, Lars
From: Lars-Göran Nord on 3 Aug 2010 19:21 "Lars-Göran Nord" <lars-goran.nordh(a)uddeholm.se> wrote in message <i39svj$q8s$1(a)fred.mathworks.com>... > "Sean " <sean.dewolski(a)nospamplease.umit.maine.edu> wrote in message <i39kh5$fbv$1(a)fred.mathworks.com>... > > "Lars-Göran Nord" <lars-goran.nordh(a)uddeholm.se> wrote in message > > > Thank you Sean, > > > > > > I will look deeper into this this evening, as I'm not an expert in this it takes some time for me to figure it all out:-) > > > Do you think I can solve all this with some help:-) I have to tell my boss this monday if its possible or not. Othervise they will outsorce the whole thing, and I really dont like that at all. And the pleasure of success is aalso very sweet:-) > > > > > > Thanks again, > > > Lars > > > > You're welcome! > > > > It's definitely doable and I think you're close to the solution. The programming aspects of this shouldn't be too hard as you have the aid of the Image Processing Toolbox. > > > > Global approach: > > -Create the skeleton with the aid of Image Analyst's example > > -Calculate the orientation at each point on the skeleton using the bwconncomp, regionprops functions. > > -To get length across pixel use the approach I gave you from above (total line length). > > -To get max crack width: at each skeleton point calculate the angle orthogonal to that point's orientation. Using this orientation figure out how many point lie along a line drawn at this angle. Use the cos()^-1 formula to get this width too. The only time this would falter would be at intersections. > > > > %%% > > %Here is the code to do the first 3 steps in one shot. I think you'll like the results! > > %%% > > % > > %SCd 08/03/2010 > > %% Load and Binarize > > I = imread('/Users/Userx/Downloads/cr1.tif'); > > I = I(:,:,1) < 52; %Binarize > > I = padarray(I,[2 2],false,'both'); %Pad the array for later use > > %% ImageAnalyst's Skeleton > > > > skel = bwmorph(I, 'skel',inf); > > % Display the skeletonized image. > > imtool(skel); > > > > % Calculate total crask > > binaryArea = sum(I(:)); > > > > % Calculate the length of all the cracks. > > skelArea = sum(skel(:)); > > > > % Divide the area by the length to get the average width. > > mean_crackWidth1 = binaryArea / skelArea > > > > %% Get Orientation at each point > > > > my_orientations = zeros(size(I)); %Preallocate > > [r c] = find(skel); %[row col] indices of points on skel > > %Note: This is why we padded earlier: > > % all r,c are greater>=3 and <= size(dim) -2 > > > > %Go to each point and calculate orientation > > for ii = 1:length(r) > > %Extract all pixels within the 5x5 window surrounding our point > > SKpart = skel((r(ii)-2):(r(ii)+2),(c(ii)-2):(c(ii)+2)); > > > > %Connected components analysis, 8 connectivity (we care about corners!) > > CC =bwconncomp(SKpart,8); > > > > %Get orientation. > > RP = regionprops(CC,'Orientation'); > > > > %Save the orientation. This may need modified if there are multiple > > %Orientations returned in the even of more than one object > > my_orientations(r(ii),c(ii)) = RP.Orientation; > > end > > > > %Sign doesn't matter > > length_orientations = abs(my_orientations); > > > > %Get angle closest to any axis > > length_orientations(length_orientations>45) = 90 - length_orientations(length_orientations>45); > > > > %Get length, preserving only those in the skeleton > > eachLength = 1./cosd(length_orientations).*double(skel); > > skelLength = sum(eachLength(:)); > > > > %Crack area divided by length > > mean_crackWidth2 = binaryArea/skelLength > > > > %Compare to Image Analyst's: > > mean_crackWidth1/mean_crackWidth2 > > Sean, > > This looks fantastic, fighting with my old car right now 1966 Impala conv. but will check later. > > Don't know how to thank you......... > > I'm very happy. > > Be back later. > > Thank you so much Sean, > > Lars Sean, I don't like the result, I love it:-) works flawlesly and gets correct answers:-) will check more tomorrow. Thanks Sean Lars
From: Sean on 4 Aug 2010 11:00 "Lars-Göran Nord" <lars-goran.nordh(a)uddeholm.se> wrote in message > Sean, > > I don't like the result, > > I love it:-) > works flawlesly and gets correct answers:-) > will check more tomorrow. > > Thanks Sean > > Lars Glad to hear, and you're welcome! I hope the car is doing well also, that sounds like a much more interesting project overall. Let me know if you need anything else. As far as the above code it should work all of the time, unless, as the comment hinted at two objects are returned. In this case you'll have to decide what to do. It would be 1 or 2 lines of code to keep only the orientation which contains the center pixel. I think I may program the max crack width algorithm I described above. It's a good excuse for me to program as opposed to journal/thesis write, which is far more enjoyable :) -Sean
From: Lars-Göran Nord on 5 Aug 2010 06:02 "Sean " <sean.dewolski(a)nospamplease.umit.maine.edu> wrote in message <i3bva5$k78$1(a)fred.mathworks.com>... > "Lars-Göran Nord" <lars-goran.nordh(a)uddeholm.se> wrote in message > > Sean, > > > > I don't like the result, > > > > I love it:-) > > works flawlesly and gets correct answers:-) > > will check more tomorrow. > > > > Thanks Sean > > > > Lars > > Glad to hear, and you're welcome! > I hope the car is doing well also, that sounds like a much more interesting project overall. > > Let me know if you need anything else. As far as the above code it should work all of the time, unless, as the comment hinted at two objects are returned. In this case you'll have to decide what to do. It would be 1 or 2 lines of code to keep only the orientation which contains the center pixel. > I think I may program the max crack width algorithm I described above. It's a good excuse for me to program as opposed to journal/thesis write, which is far more enjoyable :) > > -Sean Hi Sean, Yes my Impala SS is performing like new now, I bought it from a guy in Ottumwa (Iowa) and he got it from his father. Makes me only third owner, not bad at all for a 50 (in some months)year old car. I had one 30 years ago, but this one is in better condition despite the 30 years differance:-) so I'm pleased. I'm glad to hear you like helping out in a real world application, and I cant wait untill starting the tests and getting some info. I know this will develop into a fantastic analysing "tool". Max crack width algorithm, greeeeeaaaat!!!! Thank you, Lars
From: Lars-Göran Nord on 6 Aug 2010 12:15
"Sean " <sean.dewolski(a)nospamplease.umit.maine.edu> wrote in message <i3bva5$k78$1(a)fred.mathworks.com>... > "Lars-Göran Nord" <lars-goran.nordh(a)uddeholm.se> wrote in message > > Sean, > > > > I don't like the result, > > > > I love it:-) > > works flawlesly and gets correct answers:-) > > will check more tomorrow. > > > > Thanks Sean > > > > Lars > > Glad to hear, and you're welcome! > I hope the car is doing well also, that sounds like a much more interesting project overall. > > Let me know if you need anything else. As far as the above code it should work all of the time, unless, as the comment hinted at two objects are returned. In this case you'll have to decide what to do. It would be 1 or 2 lines of code to keep only the orientation which contains the center pixel. > I think I may program the max crack width algorithm I described above. It's a good excuse for me to program as opposed to journal/thesis write, which is far more enjoyable :) > > -Sean Hi Sean, I have tryed the script on a lot of "fake" cracks and it works all the times:-) Now to finding and counting the intersections (3 and 4 crossings) I have looked at my_orientations and can see that every intersection contains both + and - values in the columns, there is also like 4 values in the column at intersections (high angle) and 5 or maybe more values in columns at low angle intersections. Can this be used in some way??? Or is the connectivity tool with "high connectivity" the right way to go? Lars |