Implementation Run Length Smoothing Algorithm in C++
I am new with C++ and OpenCV.
I came across an interesting article:
http://crblpocr.blogspot.fr/2007/06/run-length-smoothing-algorithm-rlsa.html http://crblpocr.blogspot.fr/2007/06/determination-of-run-length-smoothing.html
There is RLSA implementation in Matlab by this thread :
http://mathworks.cn/matlabcentral/newsreader/view_thread/318198
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;
x=imread('Picture.jpg');
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
Sory, but this isn't a forum where you should ask things like: please convert my matlab program to C++. Please try it first yourself and if you have _concrete_ problems ask them here. The conversions, esp. from the second program shouldn't be too difficult: rgb2gray()->cvtColor(), histeq()->equalizeHist, im2bw -> threshold() w. Otsu, the rest are just for loops and assignments.
@Guanta thank for your advice, frankly speaking I could convert the second program to c++ but it takes a bit long since it uses the nested loop that I do not want. For the first program on the other hand, it manipulate the image in vector ways and since I am new with opencv and c++ that is why I think maybe those who are expert in these fields could help