How to set conditions to modify the pixel values: (1) at the right(x+1,y)-and-left (x-1,y); and (2) at the top (x,y-1)-and-bottom (x,y+1) with reference to the central pixel (x,y)
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello!
I need your help to 'conditionally' modify the pixels around an arbitrary selected point/pixel at (x,y) using Matlab. First, please see the following 3 x 3 grid.
top-left (x-1,y-1);
top-middle (x,y-1);
top-right (x+1,y-1);
middle-left (x-1,y);
middle-middle(x,y);
middle-right (x+1,y);
bottom-left (x-1,y+1);
bottom-middle(x,y+1);
bottom-right (x+1,y+1);
As can be seen, in the following code - and thanks to a previously requested/obtained help - I could only modify the pixels at 8 locations adjacent to (x,y) but when I set the following conditions,
sdh = 0;
sdv = 0;
sdh = abs((1/4)*(Y(1:end-2,1:end-2)-Y(1:end-2,3:end)) + (1/2)*(Y(2:end-1,1:end-2)-Y(2:end-1,3:end)) + (1/4)*(Y(3:end,1:end-2)-Y(3:end,3:end)));
sdv = abs((1/4)*(Y(1:end-2,1:end-2)-Y(3:end,1:end-2)) + (1/2)*(Y(1:end-2,2:end-1)-Y(3:end,2:end-1)) + (1/4)*(Y(1:end-2,3:end)-Y(3:end,3:end)));
if if sdh >= sdv
(x+1,y) = (1/2)*((x+1,y)+(x+2,y));
(x,y+1) = (1/2)*((x,y+1)+(x,y+2));
and
if sdh < sdv
(x,y-1) = (1/2)*((x,y-1)+(x,y-2));
(x,y+1) = (1/2)*((x,y+1)+(x,y+2));
I can't modify the pixels at the locations (x+1,y) & (x-1,y) when sdh >= sdv; and, at the locations (x,y-1) & (x,y+1) when sdh < sdv, as indicated above. Can you please have a look at the following code and help me, if possible ?
N = 8;
E = [46,38];
X = magic(N);
Y = false(N+2);
for k = 1:numel(E);
Y(2:end-1,2:end-1) = X==E(k);
Z = Y(1:end-2,2:end-1) | Y(3:end,2:end-1) | Y(2:end-1,3:end) | Y(2:end-1,1:end-2) | Y(1:end-2,1:end-2) | Y(1:end-2,3:end) | Y(3:end,1:end-2) | Y(3:end,3:end);
X(Z) = E(k);
end
0 commentaires
Réponses (1)
Image Analyst
le 18 Jan 2016
I think you can do what you want with conv2(), but I cant' figure out what you want. What does sdh and sdv represent? Why are there no comments in the code? Did you strip them out before posting or you just forgot to put them in (both are bad)?
And in words, tell me what "sdh >= sdv" represents, and, again in words, what you want to do if that condition is true. Saying that you want to "modify" the pixel is so vague that it's useless.
And, finally, what is the purpose of the "E" variable?
6 commentaires
Image Analyst
le 19 Jan 2016
You're right - I still don't understand, perhaps because you didn't answer my questions.
I don't know what the full code is. Is it the top chunk of code that talks about sdf, etc. Or is it the second chunk of code that talks about magic?
In your second chunk of code, Z will be either true or false, not an index. Why are you using Z as an index into X?
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!