Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>% Firstly, Create the images</p> <pre><code>FirstImage = [ 108 113 121 129 128 124 117 101 114 76 60 110 98 74 121 109 114 62 52 105 85 59 121 116 110 59 54 104 0 0 0 115 104 55 54 104 0 0 0 113 96 48 51 105 0 0 0 113 94 60 69 115 0 0 0 110 99 108 122 130 135 0 0 109 ]; SecondImage = [ 0 0 0 0 0 0 138 137 137 137 0 0 138 127 129 135 138 0 132 97 99 133 135 0 134 108 110 137 137 0 141 140 140 140 139 0 138 138 138 140 0 0 0 0 0 0 0 0 ]; </code></pre> <p>% Make the image binary and invert it so that the zeros in the image are 1.<br /> % This is to make it compatible with <code>bwtraceboundary</code></p> <pre><code>im = FirstImage == 0 ; </code></pre> <p>% Find the object coordinates to match the requirements of <code>bwtraceboundary</code></p> <pre><code>objectCoord = find(im); [startRow,startCol] = ind2sub(size(im),objectCoord(1) ); </code></pre> <p>% The <code>find()</code> function scans the matrix column-by-column <br /> % so we know that it will start in the top left corner and work <br /> % itself down, column-by-column. Therefore, some part of the boundary must <br /> % lie east of the first coordinate found. This is one way of finding <br /> % the starting coordinates <br /></p> <pre><code>contour = bwtraceboundary(im,[startRow startCol],'E' ); </code></pre> <p>% Mark the contour</p> <pre><code>contourimage = zeros(size(im)); contourind = sub2ind(size(contourimage),contour(:,1),contour(:,2)) contourimage(contourind) = 1; contourimage = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 1 0 </code></pre> <p><br /> % Now, this will only detect the boundary of the object itself. <br /> % We are looking for the nearest non-zero values to the boundary.<br /> % To get the nearest non-zero values,<br /> % <b>apply dilution</b> to the countour image and <br /> % then multiply it element-wise with the original image.<br /> % Calculate the mean of the non-zero values<br /></p> <p><br /> % Perform dilution<br /><br /></p> <pre><code>mask = bwmorph(contourimage,'dilate') mask = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 1 </code></pre> <p><br /><br /> % Multiply the <code>mask</code> with the original image, element-wise.<br /> % The object itself will then be zeroed out and the non-zero boundary will remain. <br /><br /></p> <pre><code>A=mask.*FirstImage A = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 105 85 59 121 116 0 0 0 104 0 0 0 115 0 0 0 104 0 0 0 113 0 0 0 105 0 0 0 113 0 0 0 115 0 0 0 110 0 0 0 130 135 0 0 109 </code></pre> <p><br /><br /> % Then calculate the average<br /></p> <pre><code>mean(A(A&gt;0)) ans = 108.6875 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload