This is probably an easy question but I am struggling with it. I have a video I'm trying to process. I'm trying to set the threshold range for the binaryimage after the image has been converted to grayscale. How do I do this such that I keep the pixels within the range 55 - 130. I have the following code but I dont know how to apply a threshold range.
grayscaleimg = rgb2gray(read(obj,1));
thresholdValue = 55;
binaryImage = grayscaleimg > thresholdValue;
binaryImage = imfill(binaryImage, 'holes');
imshow(binaryImage)
You need to do an adaptive threshold between those values.
The easiest way is to make a for cycle and evaluate each point with a if condition.
A fastest way is to do this:
grayscaleimg = rgb2gray(read(obj,1));
t1=55;
t2=130;
range=(grayscaleimg > t1 & grayscaleimg <= t2);
grayscaleimg (range)=0;
grayscaleimg (~range)=255;
imshow(grayscaleimg )
I tested it with the onion.png from Matlab and it worked.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.