Hi,
I have a slated edge image and I want to know the value of required pixel shift to make it vertical. I know the pixel value at first and end point of the edge. But want to scan the image line by line and know the values of shifted pixels for each line. But I am getting an error: *Matrix dimensions must agree for the following line: dif = abs(bw(i:j)- bw(i:j+1))
close all;clear all;clc;I=imread('C:\Users\swati\OneDrive\Documents\MATLAB\Examples\Cropped Image.jpg');figure;imshow(I); title('Original Image');impixelinfo;m=167;n=200;%Averaging The Pixels
h=ones(10,10)/100; %Create a normalized pixel; averaging filter.
I_avg=imfilter(I,h); %apply filter to image
figure(); imshow(I_avg);title(I_avg);impixelinfo;%Scanning of Image
v=I_avg(1,:); %scanning the I_avg Intensity
figure;plot(v);%converting GrayScale image to Binary Image
for x=1:200 for y=1:m if I_avg(x,y)>mean(I_avg(:)) bw(x,y)=1; elseif I_avg(x,y)<mean(I_avg(:)) bw(x,y)=0; end endendfigure; imshow(bw);impixelinfo;%finding first left most pixel when intensity drops to zero in first row
fisrt_value=zeros([1,m]);fist_value=bw(1,:)%finding first left most pixel when intensity drops to zero in last row
second_value=zeros([1,m]);last_value=bw(200,:)p2x=1;p2y=56;p1x=200;p1y=73;m=(p2y-p1y)/(p2x-p1x) %find the slope
theta=atand(m)shifted_pixel=p1y-p2y % number of shifted pixels
j=55;for i = 1:20:200 dif = abs(bw(i:j)- bw(i:j+1)) fprintf('Row Number=%0.0f',i); pos=find(dif==1) shift=p1y-pos j=j+1; i= i+1;end
Could anyone please suggest me what is wrong in my code or is there any other way to do that?
Thanks, Swati
Best Answer