フィルターのクリア

Hi All, My question to all is that .......... I have to add the elements with in the matrix.........

1 回表示 (過去 30 日間)
2 1 2
1 1 1
1 1 1
i want to add a(1,2)and a(2,1) and then multiply it with a(1,1) and so on for each element to generate a new matrix........
for a(2,2)..... we will have to do a(2,2) * ( a(1,2)+a(2,3)+a(3,2)+ a(2,1))
this a simple case and i have made the program for 3 by 3 matrix....... but how to generalize it for and n X n Matrix, where n is any number.
thanks for your guidance..........
  1 件のコメント
Offroad Jeep
Offroad Jeep 2015 年 3 月 22 日
Dear Roger Stafford, Hope you are fine. Can you please kindly check what is the problem with my code why its not generating the hysteresis loop i will be grateful........ waiting for your reply.......

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

採用された回答

Roger Stafford
Roger Stafford 2015 年 3 月 8 日
編集済み: Roger Stafford 2015 年 3 月 8 日
Let A be an n-by-n matrix.
B = [zeros(1,n+2);zeros(n,1),A,zeros(n,1);zero(1,n+2)]; % Create a border of all zeros
B = A.*(B(1:n,2:n+1)+B(3:n+2,2:n+1)+B(2:n+1,1:n)+B(2:n+1,3:n+2)); %Corrected
B will be the desired n-by-n matrix.
  5 件のコメント
Image Analyst
Image Analyst 2015 年 3 月 8 日
Roger, can you explain why this is not the original image times the convolution with a cross-shaped kernel? Even after looking at the more detailed explanation he posted, it looks like it should be. Muhammad, can you give a 5x5 matrix and the 5x5 output matrix as an example?
Offroad Jeep
Offroad Jeep 2015 年 3 月 12 日
Thanks Roger Stafford for the answer ......... it has worked........Thanks once again...........

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2015 年 3 月 7 日
It looks like you want to multiply the original image by convolution of it. Try this
kernel = [0, 1, 0; 1, 0, 1; 0, 1, 0]; % Make a "cross" or "+" shape.
sumImage = conv2(originalImage, kernel, 'same'); % Sum and add.
outputImage = originalImage .* sumImage; % Multiply.

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by