フィルターのクリア

CONDITION CHECKING R G B VALUES IN AN IMAGE WITH SCALAR USING MATLAB?

4 ビュー (過去 30 日間)
meenu v
meenu v 2018 年 5 月 29 日
コメント済み: Image Analyst 2018 年 5 月 29 日
hi, I have an image 'pq'(RGB image), which is shown below
now i want to check the following conditions by obtaining the R, G, B from the image
Where R, G, B are
R=pq(:,1)
G=pq(:,2)
B=pq(:,3)
  6 件のコメント
meenu v
meenu v 2018 年 5 月 29 日
編集済み: meenu v 2018 年 5 月 29 日
Yp,but on excecution it is showing the error
"Operands to the || and && operators must be convertible to logical scalar values."
Paolo
Paolo 2018 年 5 月 29 日
The following works for me:
num = xlsread('pq.xlsx')
R = num(:,1);
G = num(:,2);
B = num(:,3);
for ii=1:numel(R)
if(R(ii)>=1 && R(ii)<=250) && (G(ii)>=0 && G(ii)<=1) && (B(ii)>=0 && B(ii)<=255)
disp(R(ii));
end
end
Are you sure that the second condition is correct for the green value? Because you are checking between 0 and 1 only.

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

回答 (2 件)

Image Analyst
Image Analyst 2018 年 5 月 29 日
Try this:
[rows, columns] = size(pq)
for row = 1 : rows
R = pq(row, 1);
G = pq(row, 2);
B = pq(row, 3);
if (R>=1 && R<=250) && (G>=0 && G<=1) && (B>=0 && B<=255)
% and so on....
end
end

Ameer Hamza
Ameer Hamza 2018 年 5 月 29 日
You can solve the error by converting && to a single &
(R>=1 & R<=250) & (G>=0 & G<=1) & (B>=0 & B<=255)
but I doubt it will actually do, what you are thinking it will do.
  3 件のコメント
Ameer Hamza
Ameer Hamza 2018 年 5 月 29 日
But OP needs to understand that using a vector logical expression with if and while condition need to be handled carefully. The expression is essentially equaled to
if all((R>=1 & R<=250) & (G>=0 & G<=1) & (B>=0 & B<=255))
Unless the requirement is to apply the same condition to every pixel. This will probably result in a wrong logic.
Image Analyst
Image Analyst 2018 年 5 月 29 日
Yeah we talked about all this in his earlier question - about whether to use single or double ampersands. Now (in this question) he has an array pq, that seems to be a subset of all the pixels in the image. Perhaps from a masking operation - who knows? That's what I do in my answer - just the subset. Regardless, I still have doubts he knows what he wants to do, or is asking the correct question.

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

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by