我有用於運行長度編碼的Matlab代碼,我想編碼解碼。請任何人都可以幫助我製作此代碼的解碼器?我有用於運行長度編碼的matlab代碼,我想爲解碼編碼
的編碼器是如下所示:
function out = rle (image)
%
% RLE(IMAGE) produces a vector containing the run-length encoding of
% IMAGE, which should be a binary image. The image is set out as a long
% row, and the conde contains the number of zeros, followed by the number
% of ones, alternating.
%
% Example:
%
% rle([1 1 1 0 0;0 0 1 1 1;1 1 0 0 0])
%
% ans =
%
% 03453
%
level = graythresh(image);
BW = im2bw(image, level);
L = prod(size(BW));
im = reshape(BW.', 1, L);
x = 1;
out = [];
while L ~= 0,
temp = min(find(im == x));
if isempty(temp)
out = [out, L];
break;
end
out = [out, temp-1];
x = 1 - x;
im = im(temp : L);
L = L - temp + 1;
end
end
避免在您尋求解決方案時提問。而是詢問如何找到解決方案並在實現目標時展示自己的投入。 –
@advise也清楚地格式化代碼是一種重要的技能,當你試圖在代碼中進行交流時(或者至少表明你付出了一些努力來幫助別人閱讀它)。注意這一點! :) –