Thread Subject:
need matlab code for Run length smoothing algorithm.anyone?pls

Subject: need matlab code for Run length smoothing algorithm.anyone?pls

From: priya

Date: 21 Mar, 2012 08:36:17

Message: 1 of 7

The basic RLSA is applied to a binary sequence in which white pixels are represented by 0’s and black pixels by 1’s. The algorithm transforms a binary sequence x into an output sequence y according to the following rules:



1. 0’s in x are changed to 1’s in y if the number of adjacent 0’s is less than or equal to a predefined limit C.
2. 1’s in x are unchanged in y .


For example, with C = 4 the sequence x is mapped into y as follows:

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
y : 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1


When applied to pattern arrays, the RLSA has the effect of linking together neighboring black areas that are separated by less than C pixels. With an appropriate choice of C, the linked areas will be regions of a common data type.

The RLSA is applied row-by-row as well as column-by-column to a document, yielding two distinct bit-maps. Because spacings of document components tend to differ horizontally and vertically, different values of C are used for row and column processing. Thet wo bit-maps are then combined in a logical AND operation. Additional horizontal smoothing using the RLSA produces the final segmentation result.

Subject: need matlab code for Run length smoothing algorithm.anyone?pls

From: Yumnam Kirani

Date: 21 Mar, 2012 12:26:26

Message: 2 of 7

"priya" wrote in message <jkc3u1$c42$1@newscl01ah.mathworks.com>...
> The basic RLSA is applied to a binary sequence in which white pixels are represented by 0’s and black pixels by 1’s. The algorithm transforms a binary sequence x into an output sequence y according to the following rules:
>
>
>
> 1. 0’s in x are changed to 1’s in y if the number of adjacent 0’s is less than or equal to a predefined limit C.
> 2. 1’s in x are unchanged in y .
>
>
> For example, with C = 4 the sequence x is mapped into y as follows:
>
> 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
> y : 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1
>
>
> When applied to pattern arrays, the RLSA has the effect of linking together neighboring black areas that are separated by less than C pixels. With an appropriate choice of C, the linked areas will be regions of a common data type.
>
> The RLSA is applied row-by-row as well as column-by-column to a document, yielding two distinct bit-maps. Because spacings of document components tend to differ horizontally and vertically, different values of C are used for row and column processing. Thet wo bit-maps are then combined in a logical AND operation. Additional horizontal smoothing using the RLSA produces the final segmentation result.
>
I don't think it would be difficult to code. Have you tried something already?. If you can show the code, it will be easier for someone to suggest or correct your coding.
Yumnam Kirani Singh
Tronglaobi Awang Leikai

Subject: need matlab code for Run length smoothing algorithm.anyone?pls

From: priya

Date: 21 Mar, 2012 14:26:12

Message: 3 of 7

here is my sample coding for
row by row processing
clear;clc;
x=imread('Picture.jpg');
y=rgb2gray(x) ;
z=histeq(y);
t=im2bw(z);
u=double(t);
[a b]=size(u);
c=0;
for i=1:a
 for j=1:b-1
  if u(i,j)==1
    c=c+1;
    if u(i,j+1)==0||j==b-1
    if c>5;
    for k=i-c:j
    u(i,k)=0;
    end
    end
    end
  
  end
end
end
imshow(u);

Subject: need matlab code for Run length smoothing algorithm.anyone?pls

From: Yumnam Kirani

Date: 22 Mar, 2012 06:08:25

Message: 4 of 7

"priya" wrote in message <jkcoe4$h3s$1@newscl01ah.mathworks.com>...
> here is my sample coding for
> row by row processing
> clear;clc;
> x=imread('Picture.jpg');
> y=rgb2gray(x) ;
> z=histeq(y);
> t=im2bw(z);
> u=double(t);
> [a b]=size(u);
> c=0;
> for i=1:a
> for j=1:b-1
> if u(i,j)==1
> c=c+1;
> if u(i,j+1)==0||j==b-1
> if c>5;
> for k=i-c:j
> u(i,k)=0;
> end
> end
> end
>
> end
> end
> end
> imshow(u);

The corrected code for your algorithm is given below
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,[]);

Yumnam Kirani Singh
Tronglaobi Awang Leikai

Subject: need matlab code for Run length smoothing algorithm.anyone?pls

From: Bruno Luong

Date: 22 Mar, 2012 07:02:30

Message: 5 of 7

"priya" wrote in message <jkc3u1$c42$1@newscl01ah.mathworks.com>...
> The basic RLSA is applied to a binary sequence in which white pixels are represented by 0’s and black pixels by 1’s. The algorithm transforms a binary sequence x into an output sequence y according to the following rules:
>
>
>
> 1. 0’s in x are changed to 1’s in y if the number of adjacent 0’s is less than or equal to a predefined limit C.
> 2. 1’s in x are unchanged in y .
>
>
> For example, with C = 4 the sequence x is mapped into y as follows:
>
> 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
> y : 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1
>
>
> When applied to pattern arrays, the RLSA has the effect of linking together neighboring black areas that are separated by less than C pixels. With an appropriate choice of C, the linked areas will be regions of a common data type.
>

Here is a vectorized way. It needs a FEX
% http://www.mathworks.com/matlabcentral/fileexchange/29854-multiple-colon

% 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;
idx = mcolon(start(b)+1,stop(b)); % FEX function
xx(idx) = 1;
xx = reshape(xx, [], m)';
y = xx(:,2:end-1)

% Bruno

Subject: need matlab code for Run length smoothing algorithm.anyone?pls

From: Bruno Luong

Date: 22 Mar, 2012 07:20:18

Message: 6 of 7

This modified code no longer require FEX

% 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)

% Bruno

Subject: need matlab code for Run length smoothing algorithm.anyone?pls

From: priya

Date: 22 Mar, 2012 09:25:23

Message: 7 of 7

thanks a lot to

Yumnam Kirani Singh
Tronglaobi Awang Leikai
and
Bruno

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us