comparing pixels in 3x3 block

1 回表示 (過去 30 日間)
Elysi Cochin
Elysi Cochin 2020 年 1 月 2 日
編集済み: Hyeokjin Jho 2020 年 1 月 3 日
Having a matrix as shown below
Untitled.png
i wanted to take 3x3 pixel
Untitled2.png
and compare the 3 pixels (highlighted in yellow colour) with the pixel (highlighted in green colour),
and if 2 or more pixel (highlighted in yellow) has value greater than the pixel (highlighted in green) and i wanted to assign 1 to it else 0
So in this case i will get 0-1-1-0 and then convert the binary 0110 to its corresponding decimal value = 6
Then the next 3x3 pixel
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 1 月 2 日
Why 0110? Left edge of the left block, then top edge of the right block, then middle row of the right block, then middle column of the left block??

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

採用された回答

Hyeokjin Jho
Hyeokjin Jho 2020 年 1 月 3 日
編集済み: Hyeokjin Jho 2020 年 1 月 3 日
Assuming your matrix is A
% collect green pixels
query_right = A(2:end-1,3:end);
query_left = A(2:end-1,1:end-2);
query_down = A(3:end,2:end-1);
query_up = A(1:end-2,2:end-1);
% collect yellow pixels
test_column = zeros(size(A,1)-2,size(A,2)-2,3);
for j = 2:size(A,2)-1
test_column(:,j-1,1:3) = toeplitz(A(3:end,j),A(3:-1:1,j));
end
test_row = zeros(size(A,1)-2,size(A,2)-2,3);
for i = 2:size(A,1)-1
test_row(i-1,:,1:3) = toeplitz(A(i,3:end),A(i,3:-1:1));
end
% evaluate
eval_right = sum(test_column>query_right,3)>=2;
eval_left = sum(test_column>query_left,3) >=2;
eval_down = sum(test_row>query_down,3) >=2;
eval_up = sum(test_row>query_up,3) >=2;
result = eval_right*2^3 + eval_down*2^2 + eval_left*2^1 + eval_up*2^0;
For matrix given in your example, the result would be
6 7 10
2 2 10
5 5 13

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeComputer Vision with Simulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by