<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Gib,<div><br></div><div>What was the morphological operation you were doing?</div><div><br></div><div>ITK's grayscale morph operations are great. However, you need to keep in mind the cost of the different shapes of structuring elements. Unfortunately the binary methods use are single threaded algorithm with a complexity dependent on the number of boundary pixel. I am guessing this the algorithm you were using. If you have a binary image you should actually be able to use the grayscale morp ops to get the same results!</div><div><br></div><div>I am a little hesitant to share this because I haven't used it for a bit, so I'm not certain of it's current state. I spent a little time writing a new binary morph algorithm. It's only works for crosses and box/flat structuring elements. But one thread to one thread compared to the current algorithm is was more than 10X faster, and it didn't take much longer O(Radius/32) for larger structuring elements. It's also multi-threadeded so you could easily get 100X speedup compared to the current version. I've &nbsp;had similar sized data set that I could run binary morphological operations in like a minute.</div><div><br></div><div>Also keep in mind you can resample to a lower resolution for some of these larger structures, when a course segmentation is needed.</div><div><br></div><div>Brad</div><div><br></div><div><div><div>On May 23, 2013, at 5:58 PM, Gib Bogle &lt;<a href="mailto:g.bogle@auckland.ac.nz">g.bogle@auckland.ac.nz</a>&gt; wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  
  <div bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Richard, in our images dx=dy=dz, so in
      principle the closing should work fine in 3D.&nbsp; In fact I think the
      size of our images is going to make it impractical.&nbsp; I ran a test
      last night on a partial image, which is 1300x1100x200, about 1/5
      of a full image (still being generated by the microscopy rig).&nbsp; It
      was still running after 9 hours this morning, when I stopped it,
      at 100% of the 8 cores on my PC.&nbsp; This is not really practical.<br>
      <br>
      I did implement the grayscale closing, but not exactly as in your
      code.&nbsp; I've been using ITK for a while, but in a very naive way,
      and writing a lot of my own code.&nbsp; I am not a C++ expert by any
      means, and in particular I do not know anything about templates.&nbsp;
      It is not important (since I have something that works) but if you
      felt motivated to send me a simple example of a main program that
      calls doClosing() I'm sure I would find it very instructional.<br>
      <br>
      It is not clear to me yet what radius to use for the structuring
      element.&nbsp; I've tried 30, 40 and 50.&nbsp; To generate the mask I guess
      I need to set the threshold level to something like 1 or 2 - some
      experimentation is needed.<br>
      <br>
      To process the whole 3D image I'm thinking about using a
      slice-by-slice method, on the XY slices, then the YZ, then the
      XZ.&nbsp; The idea is to process each 2D slice as if to peel it, but
      leaving the image unchanged and just recording all the voxels that
      are to be removed.&nbsp; The final step will be to zero out all these
      voxels.&nbsp; I think it is necessary to do it like this to avoid
      multiple peeling.<br>
      <br>
      It will be interesting to compare the active contour approach with
      the grayscale closing method to generate the mask.<br>
      <br>
      Best regards<br>
      Gib<br>
      <br>
      On 23/05/2013 10:04 p.m., Richard Beare wrote:<br>
    </div>
    <blockquote cite="mid:CA+V7QS9h44V+7y0NA+MgJWrvP9nqsJmxs8AOjjbHmp8iUY9KVA@mail.gmail.com" type="cite">
      
      <div dir="ltr">The steps I've given should also work in 3D if the
        slice thickness is low enough to provide the connectivity
        between slices. Personally, I haven't had much luck with the
        vesselness family. My rule of thumb is that if they happen to
        work, then a simple morphological approach will probably work
        too, more reliably and with fewer parameters to fiddle :-).</div>
      <div class="gmail_extra"><br>
        <br>
        <div class="gmail_quote">On Thu, May 23, 2013 at 5:36 PM, Dan
          Mueller <span dir="ltr">&lt;<a moz-do-not-send="true" href="mailto:dan.muel@gmail.com" target="_blank">dan.muel@gmail.com</a>&gt;</span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            Hi Gib,<br>
            <br>
            Some more food for thought:<br>
            <br>
            (1) If you have a 3D image (as opposed to 2D slices) you may
            consider<br>
            using Hessian-based vesselness enhancement:<br>
            <a moz-do-not-send="true" href="http://www.itk.org/Doxygen/html/classitk_1_1Hessian3DToVesselnessMeasureImageFilter.html" target="_blank">http://www.itk.org/Doxygen/html/classitk_1_1Hessian3DToVesselnessMeasureImageFilter.html</a><br>
            <a moz-do-not-send="true" href="http://www.itk.org/Doxygen/html/classitk_1_1MultiScaleHessianBasedMeasureImageFilter.html" target="_blank">http://www.itk.org/Doxygen/html/classitk_1_1MultiScaleHessianBasedMeasureImageFilter.html</a><br>
            <a moz-do-not-send="true" href="http://www.insight-journal.org/browse/publication/314" target="_blank">http://www.insight-journal.org/browse/publication/314</a><br>
            <a moz-do-not-send="true" href="http://www.insight-journal.org/browse/publication/175" target="_blank">http://www.insight-journal.org/browse/publication/175</a><br>
            <a moz-do-not-send="true" href="http://www.insight-journal.org/browse/publication/163" target="_blank">http://www.insight-journal.org/browse/publication/163</a><br>
            <br>
            This class of filters can enhance tube-like structures (e.g.
            vessels),<br>
            while suppressing sheet like structures i.e. the outer
            border of your<br>
            object.<br>
            <br>
            (2) You could consider using an active contour method to
            segment the<br>
            outer structure (replacing step 1 in Richard's proposal
            above). You<br>
            could achieve this by initializing the contour as the edge
            of your<br>
            image, then shrink the contour until it attaches to the
            boundary of<br>
            the tissue. Then continue to follow Richard's second step
            and remove<br>
            the outer structure by erosion + masking.<br>
            <br>
            Good luck.<br>
            <br>
            Cheers, Dan<br>
            <div class="HOEnZb">
              <div class="h5"><br>
                On 23 May 2013 11:16, Gib Bogle &lt;<a moz-do-not-send="true" href="mailto:g.bogle@auckland.ac.nz">g.bogle@auckland.ac.nz</a>&gt;
                wrote:<br>
                &gt; Hi Richard,<br>
                &gt;<br>
                &gt; I don't have other staining.<br>
                &gt;<br>
                &gt; Thanks for your suggestion of a procedure. &nbsp;I will
                have to study it and<br>
                &gt; understand it, before I can comment on it.<br>
                &gt;<br>
                &gt; Gib<br>
                &gt;<br>
                &gt;<br>
                &gt; On 23/05/2013 12:25 p.m., Richard Beare wrote:<br>
                &gt;<br>
                &gt; Hi,<br>
                &gt; I'm not sure I understand completely, but here's my
                suggestion of an<br>
                &gt; approach. It may turn out to be easier if you have
                other staining too.<br>
                &gt;<br>
                &gt; 1) Segment the entire tissue - i.e generate one
                large object that contains<br>
                &gt; all your small vessels and a boundary on your layer
                that you need to peel.<br>
                &gt; More on how this might be achieved later.<br>
                &gt;<br>
                &gt; 2) Erode this object and use the eroded version to
                mask out the accidental<br>
                &gt; staining - i.e. do the peeling. Then apply your
                normal segmentation to what<br>
                &gt; is left.<br>
                &gt;<br>
                &gt; &nbsp;If you have another channel where all the tissue
                has contrast then<br>
                &gt; segmenting the tissue will be relatively easy.
                Otherwise it will be a bit<br>
                &gt; more of a challenge. My first guess if the latter
                is the case is to use 2<br>
                &gt; markers in a watershed. One marker will be the
                image border (definitely<br>
                &gt; outside the tissue). Create the marker image as
                follows.<br>
                &gt; &nbsp; &nbsp;a) Apply a large closing, say about 15% of the
                tissue size. This will<br>
                &gt; connect your interior objects together. Threshold
                the result, choose the<br>
                &gt; largest connected component, then erode that
                component a little to make sure<br>
                &gt; it stays inside the tissue and use the result as
                your foreground marker. Use<br>
                &gt; rectangular structuring elements for the closing so
                you can take advantage<br>
                &gt; of fast operations.<br>
                &gt; &nbsp; &nbsp;b) put the two markers together in an image such
                that they have different<br>
                &gt; voxel values - i.e. image border has value 2,
                inside marker from step a has<br>
                &gt; value 1.<br>
                &gt;<br>
                &gt; Use the combined image as the marker image for the
                morphological markers<br>
                &gt; filter, use the original as the control. You may
                need to smooth the original<br>
                &gt; to close boundary gaps in faint areas. You
                shouldn't need to take a gradient<br>
                &gt; because the staining forms a line which the
                watershed should find.<br>
                &gt;<br>
                &gt; Select the foreground label from the watershed
                result. Erode it a bit<br>
                &gt; (you'll need to look to confirm how much).<br>
                &gt;<br>
                &gt; If there is a gap then the watershed will leak
                through, but this won't<br>
                &gt; matter as you are going to erode the mask and areas
                with gaps don't need to<br>
                &gt; be corrected anyway.<br>
                &gt;<br>
                &gt;<br>
                &gt; On Thu, May 23, 2013 at 7:47 AM, Gib Bogle &lt;<a moz-do-not-send="true" href="mailto:g.bogle@auckland.ac.nz">g.bogle@auckland.ac.nz</a>&gt;
                wrote:<br>
                &gt;&gt;<br>
                &gt;&gt; I didn't think there would be a stock filter,
                but maybe somebody else has<br>
                &gt;&gt; addressed this.<br>
                &gt;&gt;<br>
                &gt;&gt; I have attached a typical frame. &nbsp;I can't show
                the wanted result, but I<br>
                &gt;&gt; think it's obvious when you know that the
                interior of this piece of tissue<br>
                &gt;&gt; has the blood vessels stained, while the faint
                rim is clearly not blood<br>
                &gt;&gt; vessel. &nbsp;The problem is that there will in
                general be many vessels stained<br>
                &gt;&gt; to a similar intensity as this rim.<br>
                &gt;&gt;<br>
                &gt;&gt; Gib<br>
                &gt;&gt;<br>
                &gt;&gt;<br>
                &gt;&gt; On 23/05/2013 8:53 a.m., Dženan Zukić wrote:<br>
                &gt;&gt;<br>
                &gt;&gt; I don't think there is any stock filter which
                does what you want. And I<br>
                &gt;&gt; still don't understand your situation. Can you
                show us an example slice and<br>
                &gt;&gt; wanted result?<br>
                &gt;&gt;<br>
                &gt;&gt;<br>
                &gt;&gt; On Wed, May 22, 2013 at 10:50 PM, Gib Bogle
                &lt;<a moz-do-not-send="true" href="mailto:g.bogle@auckland.ac.nz">g.bogle@auckland.ac.nz</a>&gt;<br>
                &gt;&gt; wrote:<br>
                &gt;&gt;&gt;<br>
                &gt;&gt;&gt; The reason why I don't think erode will
                work is that the part of the<br>
                &gt;&gt;&gt; image that contains the information of
                interest is made up of many<br>
                &gt;&gt;&gt; disconnected pieces, not very different
                from the boundary layer that I want<br>
                &gt;&gt;&gt; to remove. &nbsp;The only thing that I can use
                to distinguish the pixels that<br>
                &gt;&gt;&gt; need to be removed is that they are near
                the outside of the region. &nbsp;If I<br>
                &gt;&gt;&gt; apply erosion I will remove many small but
                important features (this is<br>
                &gt;&gt;&gt; labelled vasculature, and I do not want to
                lose fine capillaries).<br>
                &gt;&gt;&gt;<br>
                &gt;&gt;&gt; Gib<br>
                &gt;&gt;&gt;<br>
                &gt;&gt;&gt;<br>
                &gt;&gt;&gt; On 22/05/2013 11:12 p.m., Dženan Zukić
                wrote:<br>
                &gt;&gt;&gt;<br>
                &gt;&gt;&gt;<br>
                &gt;&gt;&gt; <a moz-do-not-send="true" href="http://www.itk.org/Doxygen/html/group__MathematicalMorphologyImageFilters.html" target="_blank">http://www.itk.org/Doxygen/html/group__MathematicalMorphologyImageFilters.html</a><br>
                &gt;&gt;&gt;<br>
                &gt;&gt;&gt; What you probably want to do is BinaryErode
                and BinaryDilate.<br>
                &gt;&gt;&gt;<br>
                &gt;&gt;&gt;<br>
                &gt;&gt;&gt; On Wed, May 22, 2013 at 7:04 AM, gib &lt;<a moz-do-not-send="true" href="mailto:g.bogle@auckland.ac.nz">g.bogle@auckland.ac.nz</a>&gt;
                wrote:<br>
                &gt;&gt;&gt;&gt;<br>
                &gt;&gt;&gt;&gt; It's hard to know what to call the
                processing I want to apply. &nbsp;I have a<br>
                &gt;&gt;&gt;&gt; set<br>
                &gt;&gt;&gt;&gt; of biological images (actually a 3D
                image, but for now I'm happy to<br>
                &gt;&gt;&gt;&gt; process<br>
                &gt;&gt;&gt;&gt; the frames one-by-one) in which the
                region of interest has an irregular<br>
                &gt;&gt;&gt;&gt; and<br>
                &gt;&gt;&gt;&gt; incomplete labelled layer around the
                boundary. &nbsp;The staining of the<br>
                &gt;&gt;&gt;&gt; layer<br>
                &gt;&gt;&gt;&gt; was unintended, and its presence
                interferes with the segmentation that I<br>
                &gt;&gt;&gt;&gt; am<br>
                &gt;&gt;&gt;&gt; doing. &nbsp;The part of the image that I
                want to extract is made up of many<br>
                &gt;&gt;&gt;&gt; disconnected objects, and there is not
                much difference in the intensity<br>
                &gt;&gt;&gt;&gt; ranges of the objects of interest and
                the unwanted edge. &nbsp;I am willing<br>
                &gt;&gt;&gt;&gt; to<br>
                &gt;&gt;&gt;&gt; trim a few pixels off the boundary all
                the way around - this will not<br>
                &gt;&gt;&gt;&gt; cause<br>
                &gt;&gt;&gt;&gt; much loss of information. &nbsp;What I need
                is way to determine a sequence of<br>
                &gt;&gt;&gt;&gt; pixels that in some sense defines the
                extent of the labelled region in<br>
                &gt;&gt;&gt;&gt; the<br>
                &gt;&gt;&gt;&gt; image, rather like a 2D shrink
                wrapping. &nbsp;I could then use this to shave<br>
                &gt;&gt;&gt;&gt; or<br>
                &gt;&gt;&gt;&gt; peel off the outer layer of pixels.<br>
                &gt;&gt;&gt;&gt;<br>
                &gt;&gt;&gt;&gt; Does this process have a name? &nbsp;Are
                there any existing filters or code<br>
                &gt;&gt;&gt;&gt; to do<br>
                &gt;&gt;&gt;&gt; this? &nbsp;Any clever suggestions (I have
                some ideas)?<br>
                &gt;&gt;&gt;&gt;<br>
                &gt;&gt;&gt;&gt; Thanks<br>
                &gt;&gt;&gt;&gt; Gib<br>
                &gt;&gt;&gt;&gt;<br>
                &gt;&gt;&gt;&gt;
              </div>
            </div>
          </blockquote>
        </div>
      </div>
    </blockquote>
  </div>

_____________________________________<br>Powered by <a href="http://www.kitware.com">www.kitware.com</a><br><br>Visit other Kitware open-source projects at<br><a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><br><br>Kitware offers ITK Training Courses, for more information visit:<br>http://www.kitware.com/products/protraining.php<br><br>Please keep messages on-topic and check the ITK FAQ at:<br>http://www.itk.org/Wiki/ITK_FAQ<br><br>Follow this link to subscribe/unsubscribe:<br>http://www.itk.org/mailman/listinfo/insight-users<br></blockquote></div><br></div></body></html>