How can I set up an RGB threshold
7 ビュー (過去 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 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!