Using radon function to find black bar position in white background image

148 views Asked by At

I want to use radon projection find horizontal position (x coordinate) of the black bar in white image (first image). However my code returns the result in third image while my expectation is second image. What is the problem, my code is here:

clear; clc;
img = rgb2gray(imread('2.png'));
bwimg = ~im2bw(img); 
[R, xp] = radon(bwimg, 0);

[h w] = size(img);    
dw = w / length(xp);
[a ix] = max(R(:,1));
pos = round(w/2 + xp(ix)*dw);
bwimg(:, pos) = 1;
figure; imshow(bwimg);

enter image description here enter image description here enter image description here

0

There are 0 answers