zzzz
zzzz

Reputation: 73

convert rgb image to binary image in R using EBImage package

I need to convert rgb image into binary image so that I can use bwlabel() function to detect the no of objects in the image in R. I have just started working on image processing, so I don't have any idea how to do it. I am using EBImage package.

Can anyone help me with this?

Thank you

Upvotes: 2

Views: 2851

Answers (1)

James King
James King

Reputation: 6365

An example with the lenac image from the package:

lenac = readImage(system.file("images", "lena-color.png", package="EBImage"))
lena = channel(lenac, "gray")
lena5 = lena > 0.5
labels = bwlabel(lena5)
max(labels)

gives 770 objects in the lena picture. Since this is a picture of a face, dividing it into objects may not make much sense. Try different values of the threshold until you get something reasonable - it depends on the type of images you are working with.

Upvotes: 3

Related Questions