How can I use RGB values in an if-else condition

3 ビュー (過去 30 日間)
AJ516
AJ516 2017 年 7 月 10 日
コメント済み: AJ516 2017 年 7 月 10 日
I'm testing a few gray-scale images. What approach would come handy when using x and y values on a pixel if my if statements were to rely of RGB Values?
The RGB values are equal to each other and the range is 0 to 1.
layout RGB [1 1 1];
Ex. if RGB>.25 use (x+1,y+1)
if RGB<.25<.5 use (x+1,y-3)
if RGB>.5 use (x+1,y)
What should I do if I want to use RGB values in my if-else statements?
  2 件のコメント
Geoff Hayes
Geoff Hayes 2017 年 7 月 10 日
AJ516 - so is RGB the pixel value and you want to determine which neighbouring pixel value to "use" for "something"?
AJ516
AJ516 2017 年 7 月 10 日
I want to use the RGB of the pixel is the brightness of the pixel to create a sloped line. The value will determine the direction of y (either up, down or remain still). The if statements will test the values in 3 situations to tell where x2,y2 will be located.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2017 年 7 月 10 日
Y = RGB(:,:,1);
xoff = zeros(size(Y));
yoff = zeros(size(Y));
xoff(:) = 1; %you used the same for all combinations
yoff(:) = 0; %for all values not overwritten below
yoff(Y < 0.5) = -3; %order is important in these next statements
yoff(Y < 0.25) = 1;
[R, C] = ndgrid(1:size(Y,1), 1:size(Y,2));
idx = sub2ind(size(Y), R + yoff, C + xoff); %note that x corresponds to columns not row
retrieved_values = Y(idx);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by