Using a variable shift to match up odd and even rows that are displaced within an image.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen

I have the following image here and as you can see there is a noticable striping artifact caused by the odd and even rows being out of sync within the image. This difference is not constant however as this displacement starts at zero and then gradually increases further down the image. The objective is the remove this striping by realigning the odd and even rows of the image. I understand that in order to accomodate for this difference in displacement, a variable shift using circshift needs to be used but I am unsure as to how to implement this. Any advice on how to begin to solve this problem would be greatly appreciated!
1 Kommentar
Jan
am 10 Mär. 2023
I'm not sure if I can see what you call "as you can see there is a noticable striping artifact".
Waht do you want to shift and why is it variable?
Antworten (1)
John D'Errico
am 10 Mär. 2023
Many unclear things here. Ok, its mostly your image that to me was unclear. :) But then, I need new eyeglasses.
Seriously, I see several sub-problems.
- How do you determine the shift? I might look at a lagged correlation between a row and the preceding row. But if the shifts seem to follow a trend, then you might be best served by using that as additional information.
- What happens at the ends? And why do you claim this is a circular shift, as opposed to stuff falling off the end of the world? I'm not sure I would expect a circular shift.
- Finally, assuming that this really is a circshift problem, the answer is easy. First, you could just use a loop, shifint each row one at a time. This would not be terribly time consuming, and I'm not sure anything more sophisticated is really justified. COULD you write a general code, that would shift each row, and do it all at once. Sure. That part is almost too easy. But a loop would have been just as easy.
A = magic(8)
rowshifts = [0 1 2 2 4 1 -1 -2];
Ahifted = rowcircshift(A,rowshifts)
function Ashifted = rowcircshift(A,rowshifts)
% rowcircshift: circularly shift each row by a specified amount
% usage: Ashifted = rowcircshift(A,rowshifts)
% A row shift of zero means that row was untouched.
% A positive row shift means the elements are shifted to the right in that row.
% first, get the row and column indices for every element of the array
[Ar,Ac] = size(A);
[R,C] = ndgrid(1:Ar,1:Ac);
% Shift the column elements by the indicated amount
C = C + rowshifts(:);
% mod does all the hard work.
C = mod(C,Ac);
C(C == 0) = Ac;
% stuff the shifted elements into the new array in the correct places
Ashifted = A;
Ashifted(sub2ind([Ar,Ac],R,C)) = A(:);
end
Anyway, your problem is in how would you determine the shift amounts. That does not seem at all clear, if I cannot see a shift in the first place.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Deep Learning Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!