How can I set up an RGB threshold
1 次查看(过去 30 天)
显示 更早的评论
I am given an image and using an input value by the user called thrper I am to calculate a threshold value for each of the color layers I have made
[image_R, image_G, image_B] = seperate_RGB_components(image_RGB)
I am to only use explicit loops such as for,if and else. In his example my professor sets thrper to .75 meaning the bottom 75% values will be converted to black and the top 25% will be converted to white (0 and 255 respectively). Will I need to use a combination of for and if loops to do so? Or is there a simpler method using only one of the explicit loops?
0 个评论
采纳的回答
David Sanchez
2013-11-5
There are easy ways to do this, but if you MUST use for loops and if conditionals:
[image_R, image_G, image_B] = seperate_RGB_components(image_RGB)
thrper = .75 % threshold
% separate the layers
image_R = image(:,:,1);
R_thres = sum(sum(image_R))/numel(image_R);
image_G = image(:,:,2);
G_thres = sum(sum(image_G))/numel(image_G);
image_B = image(:,:,3);
B_thres = sum(sum(image_B))/numel(image_B);
% apply filter
[rows cols] = size( image_R ); % number of rows and columns
% RED LAYER
for k_r = 1:rows
for k_c = 1:cols
if (image_R(k_c,k_r) < R_thres)
image_R(k_c,k_r) = 0;
else
image_R(k_c,k_r) = 255;
end
end
end
% GREEN LAYER
for k_r = 1:rows
for k_c = 1:cols
if (image_G(k_c,k_r) < G_thres)
image_G(k_c,k_r) = 0;
else
image_G(k_c,k_r) = 255;
end
end
end
% BLUE LAYER
for k_r = 1:rows
for k_c = 1:cols
if (image_B(k_c,k_r) < B_thres)
image_B(k_c,k_r) = 0;
else
image_B(k_c,k_r) = 255;
end
end
end
2 个评论
Sabanam
2014-3-27
After getting individual Segmented image R,G,B,how can i show single segmented image or combine three results?
Image Analyst
2014-3-27
What would the single image represent? Do you want to AND or OR the three individual images together? We have no idea how you want to, or should, combine your 3 images. Why not start your own thread with your own image attached?
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!