【发布时间】:2017-06-19 20:56:29
【问题描述】:
我有用于运行长度编码的 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 当您尝试使用代码进行交流时(或者至少表明您为帮助他人阅读它付出了一些努力),格式清晰的代码也是一项重要技能。注意这一点! :)
标签: matlab image-compression decoder run-length-encoding