Dear Kevin,

you can easily combine the rmObjects approach with my previous sample code,
which makes it cleaner and more compact (see the example below). Please
note, however, that rmObjects reenumerates object ids which in some
applications might be undesired.

library(EBImage)
x = readImage(system.file(file.path("images","nuclei.tif"),
package="EBImage"), all = FALSE)
y = thresh(x, w = 20, h = 20, offset = 0.1)
objects = bwlabel(y)
display(objects)

# subset for boundary pixels
dims = dim(objects)
border = c(objects[1:dims[1],1], objects[1:dims[1],dims[2]],
objects[1,1:dims[2]], objects[dims[1],1:dims[2]])

# extract object identifiers at the boundary
ids = unique(border[which(border != 0)])

# create a mask containing all objects that do not intersect the edge of
the image
inner = rmObjects(objects, ids)
display(inner)

# now you can use the inner mask to apply some function over the inner
objects, e.g. compute their intensity range:
tapply(x, inner, range)


Best,
Andrzej


On Fri, Apr 26, 2013 at 7:43 PM, Kevin Spring <kevinjspring@gmail.com>wrote:

> Thanks, this is great code.  I coded something that finds objects that are
> x% from the border of the image and t hen removes them sequentially with
> rmObjects but I think yours is more efficient than mine.
>
> Thanks again,
>
> Kevin Spring
>
>
> On Fri, Apr 26, 2013 at 11:11 AM, Andrzej Oleś <andrzej.oles@gmail.com>wrote:
>
>> Dear Kevin,
>>
>> thank you for your interest in EBImage! Although there is no ready-to-use
>> function for removing objects at image boundaries you can easily implement
>> one yourself similar to the following example:
>>
>> # ======================================
>> library(EBImage)
>> x = readImage(system.file(file.path("images","nuclei.tif"),
>> package="EBImage"), all = FALSE)
>> y = thresh(x, w = 20, h = 20, offset = 0.1)
>> objects = bwlabel(y)
>> display(objects)
>>
>> # subset for boundary pixels
>> dims = dim(objects)
>> border = c(objects[1:dims[1],1], objects[1:dims[1],dims[2]],
>> objects[1,1:dims[2]], objects[dims[1],1:dims[2]])
>>
>> # extract object identifiers at the boundary
>> ids = unique(border[which(border != 0)])
>>
>> # create a mask containing objects at the boundary
>> boundary = as.vector(objects)
>> boundary[which(!(objects %in% ids))] = 0
>> boundary = Image(boundary, dims)
>> display(boundary)
>>
>> # create a mask containing all objects that do not intersect the edge of
>> the image
>> inner = as.vector(objects)
>> inner[which(objects %in% ids)] = 0
>> inner = Image(inner, dims)
>> display(inner)
>>
>> # now you can use the inner mask to apply some function over the inner
>> objects, e.g. compute their intensity range:
>> tapply(x, inner, range)
>>
>> # ======================================
>>
>>  I hope you find this helpful.
>>
>> Best wishes,
>> Andrzej
>>
>>
>> On Tue, Apr 16, 2013 at 8:39 PM, Kevin <kevinjspring@gmail.com> wrote:
>>
>>> I did not see this listed in the documentation or in some of the great
>>> tutorials but I have an image that I need to remove the objects that
>>> intersect the edge of the image.  Does anyone know a way to do this?
>>>
>>> Thanks,
>>>
>>> Kevin
>>>         [[alternative HTML version deleted]]
>>>
>>> _______________________________________________
>>> Bioconductor mailing list
>>> Bioconductor@r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/bioconductor
>>> Search the archives:
>>> http://news.gmane.org/gmane.science.biology.informatics.conductor
>>>
>>
>>
>

	[[alternative HTML version deleted]]

