Algorithm MATLAB中的游程平滑算法(RLSA)

Algorithm MATLAB中的游程平滑算法(RLSA),algorithm,matlab,image-processing,Algorithm,Matlab,Image Processing,我在matlab中有以下RLSA代码。该算法的jist是,它尝试以指定的间距(阈值)连接区域,例如在识别文本区域时(因为文本在图像上大部分时间都固定了特定的间距)它试图将它们连接起来,以便在执行某些形态学操作时,它们能够很好地识别这些区域 1.function result=RLSA(image,hor_thresh) 2. zeros_count=0; 3. one_flag=0; 4. hor_image=image; 5. [m,n]

我在matlab中有以下RLSA代码。该算法的jist是,它尝试以指定的间距(阈值)连接区域,例如在识别文本区域时(因为文本在图像上大部分时间都固定了特定的间距)它试图将它们连接起来,以便在执行某些形态学操作时,它们能够很好地识别这些区域

1.function result=RLSA(image,hor_thresh)
2.        zeros_count=0;
3.        one_flag=0;
4.        hor_image=image;
5.        [m,n]=size(image);
6.        for i=1:m
7.            for j=1:n
8.                if(image(i,j)==1)
9.                    if(one_flag==1)
10.                        if(zeros_count<=hor_thresh)
11.                            hor_image(i,j-zeros_count:j-1)=1;
12.                        else
13.                           one_flag=0;
14.                        end
15.                        zeros_count=0;
16.                   end
17.                    one_flag=1;
18.                else 
19.                    if(one_flag==1)
20.                        zeros_count=zeros_count+1;
21.                    end
22.                end
23.            end
24.        end
25.        result= hor_image;
26.        end
有人能给我解释一下算法对文本图像的作用,以及为什么这个代码不能对所有的阈值都起作用?
此外,我是否需要对该代码进行两次传递(如所给出的链接中所述),一次用于水平方向,另一次用于垂直方向,并且逻辑上,它们或所述代码已经处理好了?

这一切都取决于您随Hor_Thresh一起传递的图像。我想问题是j-zeros_计数可能是负数。如果图像的一列有一个1,但在另一列的20像素范围内,有一个1,这是可能的。然后,设置为1的范围将跨越2列

我真的不知道该算法试图做什么,但它似乎是在处理二进制图像(但不是明确的)。它将计数 从参数的名称猜测,我希望在2个for循环之间看到一些重置代码。Hor_Threshold表示水平阈值,即每列重置一次。 因此,在i和j循环之间,我认为您需要重置两个标志: 零计数=0; 一个_标志=0

我已经有很长一段时间没有使用Matlab了,我已经使用了一种类似的语言IGORPro有一段时间了,所以我用Igor进行了测试。这是转换后的函数:

Function/Wave RLSA(image,hor_thresh)
    Wave Image
    Variable Hor_Thresh

    Variable zeros_count = 0;
    Variable one_flag = 0;
    Duplicate/FREE Image, hor_image
    Variable m = DimSize(Image,0)
    Variable n = DimSize(Image,1)
    Variable i, J
    for (i = 0;i < m;i += 1)
        for (j = 0;j < n;j += 1)
            if (image[i][j] == 1)
                if (one_flag == 1)
                    if (zeros_count <= hor_thresh)
                        hor_image[i][j-zeros_count,j-1] = 1;
                    else
                        one_flag = 0;
                    endif
                    zeros_count = 0;
                endif 
                one_flag = 1;
            else 
                if (one_flag == 1)
                    zeros_count += 1;
                endif
            endif
        endfor
    endfor
    return hor_image;
end //RLSA
抛出与您相同的错误。
因此,我在图像中有两个1,它们由3个零(调试器可能会告诉您是否在第11行设置了断点,并观察
j
zero\u count
的值。
Function/Wave RLSA(image,hor_thresh)
    Wave Image
    Variable Hor_Thresh

    Variable zeros_count = 0;
    Variable one_flag = 0;
    Duplicate/FREE Image, hor_image
    Variable m = DimSize(Image,0)
    Variable n = DimSize(Image,1)
    Variable i, J
    for (i = 0;i < m;i += 1)
        for (j = 0;j < n;j += 1)
            if (image[i][j] == 1)
                if (one_flag == 1)
                    if (zeros_count <= hor_thresh)
                        hor_image[i][j-zeros_count,j-1] = 1;
                    else
                        one_flag = 0;
                    endif
                    zeros_count = 0;
                endif 
                one_flag = 1;
            else 
                if (one_flag == 1)
                    zeros_count += 1;
                endif
            endif
        endfor
    endfor
    return hor_image;
end //RLSA
Make/N=(24,24) Image
Image = 0
image[0][22] = 1
image[1][2] = 1
RLSA(image,20)