필터 지우기
필터 지우기

How can I set up an RGB threshold

조회 수: 1 (최근 30일)
Feynman
Feynman 2013년 11월 5일
댓글: Image Analyst 2014년 3월 27일
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?

채택된 답변

David Sanchez
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
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
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개)

Feynman
Feynman 2013년 11월 5일
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);
This code won't calculate the range of the image RGB will it? The function should prompt the user to enter a percentage to be saved as thrper and by finding the range of values in the image layer find the points in which the pixel value should be reset to 0 or 255 so if the red layer had values ranging from -100 to 300 the threshold value should be 200 so any pixel below 200 will be set to 0 and any value above 200 will be set to 255

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by