i am unable to zigzag scan image
조회 수: 6 (최근 30일)
이전 댓글 표시
i am using this code kindly help me to solve
댓글 수: 6
Walter Roberson
2018년 3월 31일
Why are you reshaping Red into a 3D array? Why are you reshaping it at all? Why not just ZigZagscan(red) ?
답변 (1개)
Guillaume
2018년 3월 28일
편집: Guillaume
2018년 3월 28일
You cannot copy the body of a function into your code and expect it to work like a script. The function needs to be in its own m-file which you call from your script. Hence your script should only be:
X=imread('lena1.jpg');
imshow(X);
v = ZigZagScan(X);
Saying that, this ZigZagScan function is not particularly well written and assumes the input is a square matrix.
Below, a simpler code. Note this is also a function, so you'll have to put it into its own m-file named antizigzag.m
function v = antizigzag(X)
%author: G. de Sercey, University of Brighton
%BSD license
%input: X a 2D matrix, not necessarily square
%output: v a row vector of the anti-diagonals of the matrix scanned in a zigzag fashion
validateattributes(X, {'numeric'}, {'2d'});
X = fliplr(X); %flip X so the anti-diagonals become diagonals
v = arrayfun(@(d) diag(X, d), size(X, 2)-1:-1:1-size(X, 1), 'UniformOutput', false); %get the diagonals
v(1:2:end) = cellfun(@flip, v(1:2:end), 'UniformOutput', false); %flip odd diagonals
v = vertcat(v{:}).'; %concatenate the whole lot in a row vector
end
댓글 수: 7
Walter Roberson
2018년 3월 30일
jpeg images are 3 dimensional more than 99.9% of the time. You cannot apply zigzag or anti-zigzag routines to them as a whole: you can only apply it to one channel at a time, or else reshape the whole thing as if it were 2D and process the reshaped version. Or convert to grayscale and work with that.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!