Is there any R function to convert grey scale image to binary image. There is one to convert from RGB to Grey but I want to convert Grey to Binary.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You didn’t say what class or “typeof” your data is, so I’m going to provide an answer in a simple case. Suppose your image is an array of integers. These integers range from 0 to, say 512 for a 9-bit greyscale image. You need to decide what the cutoff point is for 0 vs. 1 in your binary image. Then
bin_image <- round(grey_image/max(grey_image),0)should do it. If your data range from 0 to 1, do a similar operation but adjust the rounding parameters.
Edit: ooops, I left out a choice of cutoff level. Replace
max(grey_image)withK*max(grey_image)whereK = 1for cutting at half-max,K>1to cut higher andK<1to cut lower.