Finding value of a matrix
2 ビュー (過去 30 日間)
古いコメントを表示
I have a 3x3 matrix, for example:
d=rand(3,3)
Now i want to implement the equation
V=1/2(d(q4,q5)+d(q5,q6))
where q5 is the centre pixel
q4,46 are neighbouring pixels
for example
d= q1 q2 q3
q4 q5 q6
q7 q8 q9
please assist
1 件のコメント
採用された回答
Walter Roberson
2012 年 12 月 19 日
Hard to tell. You might be asking for
oldMatrix = double(ImageMatrix);
NewMatrix = ( oldMatrix(:,1:end-1) + oldMatrix(:,2:end) ) ./ 2;
But perhaps your "d" matrix is trying to talk about weighting the pixel values ? If so then let w1 be the weight for what you showed as d(q4,q5), and let w2 be the weight for what you showe as d(q5,q6), and then
NewMatrix = ( w1 .* oldMatrix(:,1:end-1) + w2 .* oldMatrix(:,2:end) ) ./ 2;
12 件のコメント
その他の回答 (2 件)
Muruganandham Subramanian
2012 年 12 月 19 日
編集済み: Muruganandham Subramanian
2012 年 12 月 19 日
d=ones(3);
V=1/2*(d(d(2,2),d(2,2))+d(d(2,2),d(2,3)))
but, If you're using rand(), d(2,2),etc.. can't be accessible, if not using ceil() or floor()..Is this you want?
7 件のコメント
Walter Roberson
2012 年 12 月 19 日
The confusion is between pixel locations and pixel values. You wrote the question with d(q4,q5) which based on the way you wrote the question is trying to access the matrix d() at row index which is the value of the pixel you labeled q4, and column index which is the value of the pixel you labeled q5.
Muruganandham Subramanian
2012 年 12 月 19 日
@FIR, I din't worked on images, anyway, by using imread() read your image and do the calculation
Image Analyst
2012 年 12 月 19 日
By chance do you mean just convolution with a [1 2 1]/4 kernel, where you take the average of the left pair of pixels and the right pair of pixels? If so, you'd need to extract each color plane first and then use conv2() to get the output image one color plane at a time.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!