<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi David,<br>
<br>
is it possible to connect the vtkImageConnectivityFilter to other
filters of VTK that do not have vtkImageData as output?<br>
<br>
I have a pipleline that creates vtkPolyData as output, so I cannot
use your filter directly. Using this example:<br>
<a class="moz-txt-link-freetext" href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataToImageData">http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataToImageData</a><br>
creates one single region. I printed the number of regions and the
size by<br>
<br>
s = c->GetExtractedRegionSizes();<br>
for (int i = 0; i < c->GetNumberOfExtractedRegions(); i++)<br>
{<br>
cout << "num: " <<
c->GetNumberOfExtractedRegions() << endl; //1<br>
cout << "size: " << s->GetTuple1(i);
//1.27008e+07<br>
}<br>
<br>
- Imre<br>
<br>
<div class="moz-cite-prefix">Am 02.01.2016 um 21:45 schrieb David
Gobbi:<br>
</div>
<blockquote
cite="mid:CANwS1=Fugzi6JW6xivQq8iBbiME7ffYoEq7d3Wm51xjUV=jzLw@mail.gmail.com"
type="cite">
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote">On Sat, Jan 2, 2016 at 1:06 PM, Imre
Goretzki <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:goretzki.imre@gmail.com" target="_blank">goretzki.imre@gmail.com</a>></span>
wrote:
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"> <br>
Yes they can be partially outside the mask because I
neither know the sizes and locations of the regions I
want to keep nor the sizes and locations of the regions
I want to discard for both input image and mask image
(the mask changes dynamically)<br>
<br>
Ok so in later progress I could use the mask as the
second input (the stencil) and this removes the regions?<br>
</div>
</blockquote>
<div><br>
</div>
<div>The vtkImageConnectivityFilter ignores any pixels that
are outside the stencil (so that might be the reverse of
what you want, since you want to ignore the regions that
are inside your mask).</div>
<div><br>
</div>
<div>If a region is partly outside the stencil, then only
the part that is outside will be ignored. The rest would
be counted. As far as I understand, that is not what you
want. You would want the entire region to be ignored,
right?</div>
<div><br>
</div>
<div>Is there any reason that you even need a "mask"? Would
it be just as good if you could specify the unwanted
regions by giving just one point in each unwanted region,
i.e. the user would use the mouse to click on the unwanted
regions?</div>
<div><br>
</div>
<div>Actually, instead of using an input mask, it seems that
it would be best to allow vtkImageConnectivityFilter to
assign a different label value to each region. Then, once
you know which labels correspond to which regions, you
could pass this label image through a lookup table that
colors all of the unwanted regions black.</div>
<div><br>
</div>
<div> - David</div>
<div><br>
</div>
<div><br>
</div>
<div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"> My current code
lets me get the regions I want to discard by storing the
polydata output of vtkPolyDataConnectivityFilter and
then iterate over the cells and their points<span><br>
<br>
for (int i = 0; i <
filter->GetNumberOfExtractedRegions(); i++)<br>
{<br>
</span> vtkSmartPointer<vtkPolyData>
extractRegionData =
vtkSmartPointer<vtkPolyData>::New(); //fast<br>
extractFilter->InitializeSpecifiedRegionList();
//fast<br>
extractFilter->AddSpecifiedRegion(i); //fast<br>
extractFilter->Modified(); //fast<br>
extractFilter->Update(); //very long<br>
extractRegionData->DeepCopy(extractFilter->GetOutput());
//fast<br>
regionList.push_back(extractRegionData); //fast<span><br>
}<br>
for (int i = 0; i <
filter->GetNumberOfExtractedRegions(); i++)<br>
{<br>
</span> // some other operations<br>
}<br>
<br>
The update() process takes a very long time. As an
example, if I have about 200 regions, this would take
about 10 minutes. All other following operations on the
data and/or a vtkPolyDataConnectivityFilter do not take
so long.<span><font color="#888888"><br>
<br>
- Imre</font></span>
<div>
<div><br>
<br>
<div>Am 02.01.2016 um 20:48 schrieb David Gobbi:<br>
</div>
<blockquote type="cite">
<div dir="ltr">Thanks, that helps. Here is my
understanding so far:
<div><br>
</div>
<div>1) The mask is, originally, a polydata
contour.</div>
<div>2) The mask indicates the regions you do
not want.</div>
<div>3) The mask will be converted into a binary
image before use.</div>
<div><br>
</div>
<div>What I still need to know is:</div>
<div><br>
</div>
<div>3) Will some regions be partially within
and partially outside the mask? Or will they
always be entirely within or entirely outside?</div>
<div><br>
</div>
<div>The vtkImageConnectivityFilter takes two
inputs: the first input is just an image (of
course) and the second input (which is
optional) is an image stencil (essentially a
binary image). There is a filter called
vtkPolyDataToImageStencil which can be used
create this second input from a vtkPolyData
object.</div>
<div><br>
</div>
<div> - David</div>
<div><br>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Sat, Jan 2, 2016 at
12:32 PM, Imre Goretzki <span dir="ltr"><<a
moz-do-not-send="true"
href="mailto:goretzki.imre@gmail.com"
target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:goretzki.imre@gmail.com">goretzki.imre@gmail.com</a></a>></span>
wrote:<br>
<blockquote class="gmail_quote"
style="margin:0 0 0 .8ex;border-left:1px
#ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"> I've
drawn another image you could look at. The
left image is the input data from which I
would like to extract the regions. Here
every region I would like to keep is
painted green. The other two regions, that
are painted red, have points that are
located inside a region in the binary
mask.<br>
<br>
<br>
For all points <i>P</i> in all regions <i>R</i>
of image 1 with binary mask <i>B</i><br>
<br>
If B_P == 255<br>
color region <i>R</i> red<br>
else<br>
color region <i>R</i> green<span><font
color="#888888"><br>
<br>
- Imre</font></span>
<div>
<div><br>
<br>
<div>Am 02.01.2016 um 20:16 schrieb
David Gobbi:<br>
</div>
<blockquote type="cite">
<div dir="ltr">Sorry, but I still
don't follow your explanation. I
have some vague idea of what you
are trying to do, but I don't
understand well enough to give you
any concrete advice. Can you try
focussing on just one specific
aspect of the problem, and then
once I've understood that one
aspect, we can move forward from
there?
<div><br>
</div>
<div> - David</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Sat,
Jan 2, 2016 at 11:46 AM, Imre
Goretzki <span dir="ltr"><<a
moz-do-not-send="true"
href="mailto:goretzki.imre@gmail.com"
target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:goretzki.imre@gmail.com">goretzki.imre@gmail.com</a></a>></span>
wrote:<br>
<blockquote class="gmail_quote"
style="margin:0 0 0
.8ex;border-left:1px #ccc
solid;padding-left:1ex">
<div bgcolor="#FFFFFF"
text="#000000"> Mh ok, I
guess I did not explained my
problem well enough.<br>
<br>
The
vtkPolyDataConnectivityFilter
returns regions, either the
largest, specified, seeded
or all regions (your filter
returns largest, seeded or
all). I'm interessted in the
following:<br>
<br>
- all regions<br>
- specified regions.<br>
<br>
The problem is not the
filter, the performance or
possible memory leaks, I
need the region's polydata
representation because I
have a second object
(vtkImageData or
vtkPolyData, binary mask)
that has some additional
information, that are not
represented by the data (the
input for the
vtkImageConnectivityFilter).<br>
<br>
Imagine the input for the
filter as image 1 and the
mask as image 2. Both images
have the same dimensions in
all 3 directions (x, y, z)
but contain different
information.<br>
<br>
image 2 will be transformed
to a binary image mask<br>
<br>
from image 1 i need to
extract regions, but if some
(unknown) regions have
points that are located in
the binary image mask, I do
not want these regions to be
contained in the extracted
region list.<br>
<br>
So it's not about your
filter or the performance,
but I have some problems
using this filter for my
issue, because I cannot
reach the region's polydata.<br>
<br>
I hope this helps.<span><font
color="#888888"><br>
<br>
- Imre</font></span>
<div>
<div><br>
<br>
<div>Am 02.01.2016 um
18:54 schrieb David
Gobbi:<br>
</div>
<blockquote type="cite">
<div dir="ltr">Hi
Imre, Happy New
Year!
<div><br>
</div>
<div>I've read your
email few times,
and I feel that I
must be missing
some important
because there are
several things
that I don't
understand about
it.</div>
<div><br>
</div>
<div>The
vtkImageConnectivityFilter
is essentially
just a connected
component filter.
In the output of
this filter, all
pixels outside the
mask will be
colored black
(they will have a
value of zero).
So what I don't
understand about
your email is why
you say that
non-rectangular
regions are a
problem. Are you
just worried about
the wasted memory?</div>
<div><br>
</div>
<div> - David</div>
<div><br>
<div
class="gmail_extra"><br>
<div
class="gmail_quote">On
Sat, Jan 2,
2016 at 9:00
AM, Imre
Goretzki <span
dir="ltr"><<a
moz-do-not-send="true" href="mailto:goretzki.imre@gmail.com"
target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:goretzki.imre@gmail.com">goretzki.imre@gmail.com</a></a>></span>
wrote:<br>
<blockquote
class="gmail_quote"
style="margin:0px
0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div
bgcolor="#FFFFFF"
text="#000000">
Hey David,<br>
<br>
first of all:
Happy new year
:)<br>
<br>
I have some
questions
about your
filter. First
of all in part
A of the
attached
image, is my
understanding
of extents, so
if you have a
region, you
will get the
x_min/x_max,
y_min/y_max
(and
z_min/z_max
for 3D). If
you do not
have
rectangular
regions than
you could have
some problems
(see part A
and B). In
part B you see
my mask. The
red rectangle
shows the case
that the 4
corners of a
2D region
cannot be
directly
checked,
because the
region that
lies within
this rectangle
has little
matches with
the mask (none
of the 4
corners are
within the
mask). The
green
rectangle has
3 out of 4
edges that lie
within the
mask.<br>
<br>
Part C shows
one of the
worst cases of
this approach
(using
extents)
because there
is so much
space that
does not
belong to the
actual region.<br>
<br>
My question:
Is it possible
to extend your
filter to
directly store
the region
data (for each
region, for
example as
vtkImageData)
if the
extraction
mode is set to
"All"?<span><font
color="#888888"><br>
<br>
- Imre</font></span>
<div>
<div><br>
<br>
<div>Am
29.12.2015 um
13:27 schrieb
Imre Goretzki:<br>
</div>
<blockquote
type="cite">
Hi David,<br>
<br>
thank you.
I'll take a
look at your
class.<br>
<br>
Regards<br>
Imre<br>
<br>
<div>Am
29.12.2015 um
13:07 schrieb
David Gobbi:<br>
</div>
<blockquote
type="cite">
<div dir="ltr">Hi
Imre,
<div><br>
</div>
<div>I have a
connectivity
filter that
works directly
on images, it
can label
connected
regions
according to
size and it
should be much
faster
(probably
1000x) than
doing voxel
checks via
polydata:</div>
<div><a
moz-do-not-send="true"
href="https://github.com/dgobbi/AIRS/blob/master/ImageSegmentation/vtkImageConnectivityFilter.h"
target="_blank"><a class="moz-txt-link-freetext" href="https://github.com/dgobbi/AIRS/blob/master/ImageSegmentation/vtkImageConnectivityFilter.h">https://github.com/dgobbi/AIRS/blob/master/ImageSegmentation/vtkImageConnectivityFilter.h</a></a></div>
<div>I'll
probably be
contributing
this filter to
VTK sometime
in the near
future.</div>
<div><br>
</div>
<div> - David</div>
<div><br>
<div
class="gmail_extra"><br>
<div
class="gmail_quote">On
Tue, Dec 29,
2015 at 4:02
AM, Imre
Goretzki <span
dir="ltr"><<a
moz-do-not-send="true" href="mailto:goretzki.imre@gmail.com"
target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:goretzki.imre@gmail.com">goretzki.imre@gmail.com</a></a>></span>
wrote:<br>
<blockquote
class="gmail_quote"
style="margin:0px
0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div
bgcolor="#FFFFFF"
text="#000000">
Is there an
easier way in
ITK?<br>
<br>
Thanks<span><font
color="#888888"><br>
Imre</font></span>
<div>
<div><br>
<br>
<div>Am
28.12.2015 um
23:38 schrieb
Imre Goretzki:<br>
</div>
<blockquote
type="cite">
Hey guys,<br>
<br>
I use the
vtkPolyDataConnectivityFilter
from polydata
to extract
several
different and
more or less
unknown
regions. <br>
My problem is
that I want to
extract
regions from
this filter,
but if I do
this, the
update process
for all
regions takes
up to
10minutes:<br>
<br>
filter->SetExtractionModeToAllRegions();<br>
filter->Update();<br>
...<br>
<br>
for (int i =
0; i <
filter->GetNumberOfExtractedRegions();
i++)<br>
{<br>
extractFilter->InitializeSpecifiedRegionList();<br>
extractFilter->AddSpecifiedRegion(i);<br>
extractFilter->Modified();<br>
extractFilter->Update();<br>
extractRegionData->DeepCopy(extractFilter->GetOutput());<br>
}<br>
extractFilter->InitializeSpecifiedRegionList();<br>
<br>
Background for
this: I want
to use the
points of each
region to
check whether
they lie
within an
object in my
binary<br>
mask image. So
the pipeline
would be like
this:<br>
<br>
1) Get all
Regions <br>
2) get
region <i>i</i><br>
3)
get points of
region <i>i</i><br>
4) check if
point <i>j</i>
lies within
the binary
mask <i>B</i>
(<i>B</i>_<i>j</i>
== 255)<br>
4a) if true
then add
region to the
extractFilter
and break
(-> next
region <i>i</i>)<br>
4b) if false
then continue
with next
point <i>j</i><br>
5) Mark all
regions red
(done easily)<br>
6) Mark some
regions green
that are above
a specific
size (can be
accessed with
filter->GetRegionSizes()
)<br>
7) Mark some
regions yellow
(the regions
that are
extracted
during step
1-4a) <br>
<br>
I do not know
if the
PolyDataConnectivityFilter
is the right
class for
this, I think
it is. <br>
If I store the
extractRegionData
in a vector,
all regions
have the same
number of
points (which
is kind of
strange) but
different
number of
cells (region
size == number
of cells is
correct).<br>
<br>
I would now
try to get the
points from
the cells and
check the
binary mask,
because the <br>
<br>
vtkPolyData->GetNumberOfPoints()<br>
<br>
and<br>
<br>
vtkPolyData->GetPoint(pointCounter,
point); <br>
<br>
are not
working
correctly in
this scenario
(all regions
are extracted
because every
single region
has every
point?<br>
i did not
verify my
guess but I
think there
would be the
problem)<br>
<br>
The binary
mask is a
vtkImageData,
that could be
transformed to
vtkPolyData.<br>
The input
image (already
filtered with
vtkMarchingCubes)
and the binary
mask have the
same
dimensions
(x,y,z).<br>
<br>
I hope you can
imagine what
I'm trying to
do and have
some tips for
me, if my
approach is
correct.<br>
<br>
Regards<br>
Imre</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</blockquote>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</blockquote>
<br>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</blockquote>
<br>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</blockquote>
<br>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</blockquote>
<br>
</body>
</html>