# Implementation Run Length Smoothing Algorithm in C++

I am new with C++ and OpenCV.

I came across an interesting article:

There is RLSA implementation in Matlab by this thread :

In link above : Matlab Code Vector Version by Bruno Luong

% Data
x=[0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 0;
0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0]
C = 4;
% Engine
[m n] = size(x);
xx = [ones(m,1) x ones(m,1)];
xx = reshape(xx',1,[]);
d = diff(xx);
start = find(d==-1);
stop = find(d==1);
lgt = stop-start;
b = lgt <= C;
d(start(b)) = 0;
d(stop(b)) = 0;
yy = cumsum([1 d]);
yy = reshape(yy, [], m)';
y = yy(:,2:end-1)


Normal Version by Yumnam Kirani Singh

clear;clc;
y=rgb2gray(x) ;
z=histeq(y);
t=im2bw(z);
u=double(t);
[a b]=size(u);
for i=1:a
c=1;
for j=1:b
if u(i,j)==1
if (j-c)<=5
u(i,c:j)=1;
end
c=j;
end
end
if (b-c)<=5
u(i,c:b)=1;
end
end
imshow(u,[]);


Anyone has experience in C++ could implement it with OpenCV, C++ using Mat Structure??

Thank

edit retag close merge delete