How do I perform an RGB threshold?
24 views (last 30 days)
Show older comments
Create a function called Perform_RGB_threshold. Your function header should look like:
function [threshold_RGB] = Perform_RGB_threshold(image_RGB, thrper)
The result of performing a LOG operation on the sample image that you download will be an array with a very wide range of numbers (approximately -2000 to +2000). As a result, you will see a double line effect on the edges of the image after you perform the LOG. We would like to clean up those edges so that we only see nice clean white lines on a black background. Thresholding is an operation often used to generate black and white images. For this function we’ll also use it to rescale the image so that all of the final values fall in the range 0 to 255. (Although in this case, the output pixels will ONLY be 0 or 255.) You will want to convert each pixel in the input image to either a black pixel (value 0) or a white pixel (255) depending on whether the pixel in the input image image_RGB is less than a threshold value or not. You will calculate a threshold value for each color layer in the image based on the threshold percent (thrper) given as an input parameter. For example, the main script file calls this function with the value .75 as thrper. This means that the function will convert pixels with values in the bottom 75% of the full range to black (new value = 0) and the pixels with values in the top 25% of the full range to white (new value = 255). For example, if the red layer values range from -100 to +300, then the red threshold value for a thrper of .75 would be 200.
0 Comments
Accepted Answer
Image Analyst
on 6 Nov 2013
Edited: Image Analyst
on 9 Mar 2020
You forgot to add the "homework" tag like you were supposed to so I added it for you. Here are some helpful code snippets:
% Extract the individual red, green, and blue color channels.
% (Note: rgbImage might be after you've taken the log of it.)
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
maxGrayLevelR = max(redChannel(:));
minGrayLevelR = min(redChannel(:));
% Convert percentage threshold into an actual number.
thresholdLevel = minGrayLevelR + thrper*(maxGrayLevelR - minGrayLevelR);
binaryImageR = redChannel > thresholdLevel;
That should be more than enough for you to complete your assignment - fill in the missing lines, do things in all color channels, etc.
4 Comments
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!