How can i write this equation in matlab ??????

(v(i,j))^(k+1)= (1-ω)(v(i,j))^(k)-ω[(W1(i,j)(v(i+1,j))^(k)+ W2(i,j)(v(i-1,j))^(k+1)+ W3(i,j)(v(i,j+1)^(k)+ W4(i,j)(v(i,j-1))^(k+1)(/(W i,j)]
v matrix k iteration W may by matrix (have i &j) w constant

Réponses (2)

John Petersen
John Petersen le 18 Sep 2013
The trick is to update v(i-1,j) and v(i,j-1) without updating v(i+1,j) and v(i,j+1) before going on the v(i,j). After that do:
v(i,j)= (1-ω)*v(i,j) - ω*[(W1(i,j)*v(i+1,j) + W2(i,j)*v(i-1,j) + W3(i,j)*v(i,j+1) + W4(i,j)*v(i,j-1))/W(i,j)]

3 commentaires

Mary Jon
Mary Jon le 18 Sep 2013
where is the (k) number of iteration?? I am have two matrices new matrix with iteratuon (k+1) and old matrix with iteration(k)
This equation consist of two part, one of it i take it from initial matrix (k) and second part with (k+1)
Image Analyst
Image Analyst le 18 Sep 2013
convolution, conv2(), and imfilter() do this "trick" inherently and efficiently. With your code, as you move over to the next j, your v(i,j) will now be the new v(i, j-1) and will be affected. So it will have some kind of recursive/hysteresis effect or trailing blur or something that's not right. imfilter() and conv2() do not suffer from this. If she insists on using two nested for loops (a much less efficient approach especially for larger windows) then she'll have to at least assign the result (right hand side of the equation) to a new output variable, like vout(i,j), not the original input variable.
conv2() and imfilter are more efficient because they only need to read in and discard a few of the pixels on the edge, not the whole array. For example with a 7x7 window, you have 49 elements/pixels in the window but as you slide over one pixel you only need to read in 7 new pixels, not all 49.
Mary Jon
Mary Jon le 21 Sep 2013
I do conv2(), and imfilter() ,but no result getting yet ,where is wrong?

Connectez-vous pour commenter.

Image Analyst
Image Analyst le 18 Sep 2013
Modifié(e) : Image Analyst le 18 Sep 2013
Looks like unsharp masking, so you can do this
kernel = [0, W1, 0; W3, 0, W4; 0, W2, 0];
filtered = conv2(vk, kernel, 'same');
vk = (1-omega)*vk + filtered./W;

8 commentaires

Mary Jon
Mary Jon le 18 Sep 2013
i need put this equation in to many(nested) for loop with respect to i and j (row ,column) and i get this error in command window!!!
??? Error using ==> horzcat All matrices on a row in the bracketed expression must have the same number of rows.
Error in ==> SOR at 69 kernel = [0, W2, 0;W4, 0, W3;0, W1, 0];
Image Analyst
Image Analyst le 18 Sep 2013
Modifié(e) : Image Analyst le 18 Sep 2013
No you don't. The 2D/nested looping is done internally inside conv2(). Definitely do not put conv2() inside a loop! That call to conv2() processes the entire image.
Mary Jon
Mary Jon le 19 Sep 2013
Can i do [ conv2() ]with matlab 7
Image Analyst
Image Analyst le 19 Sep 2013
Yes, it's been in base MATLAB for a long long time.
Mary Jon
Mary Jon le 19 Sep 2013
I get this error again!!!!!!
Error using ==> horzcat All matrices on a row in the bracketed expression must have the same number of rows.
Error in ==> SOR at 73 kernel = [0, W1, 0; W3, 0, W4; 0, W2, 0];
and looping is done internally inside conv2(),as you tell me, I want specify the began of loop and end of the loop such i=105,j=[2:13, 22:32] then i=106 ,j=2:32 and so on, in two case I must used this eq.
Image Analyst
Image Analyst le 19 Sep 2013
What are the values of W1, W2, etc.? They're probably arrays, what are they?
Image Analyst
Image Analyst le 20 Sep 2013
Just tell me what it's supposed to do. It looks like you might be able to use convolution but if W1, etc. are not constants, then maybe not. I really need to know what the intent of that code is. For example if it's to do unsharp masking then you should use a different output variable if you're going to do it in a loop so that you avoid hysteresis. I suspect that you transcribed the equation incorrectly but I can't say exactly how to fix it unless I know what you want to accomplish. John's code will probably work in that it will do what you tried to do, but I'm not sure that is really what you want to do because I don't feel that you described in words properly what you want to do.
Mary Jon
Mary Jon le 20 Sep 2013
Modifié(e) : Mary Jon le 1 Oct 2013
when using this "trick"
Z = zeros(size(W1)); kernel = [Z, W1, Z; W3, Z, W4; Z, W2, Z]; filtered = conv2(vk, kernel, 'same'); vk = (1-w)*vk + filtered./W(i,j);
get this error
Undefined function or variable "vk".
Error in ==> SOR at 69 filtered = conv2(vk, kernel, 'same');

Connectez-vous pour commenter.

Catégories

En savoir plus sur Read, Write, and Modify Image dans Centre d'aide et File Exchange

Question posée :

le 18 Sep 2013

Community Treasure Hunt

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

Start Hunting!

Translated by