MATLAB Image Analysis -
i want analyse picture of wires embedded in rubber casing , find distance between wires , edge (image attached).
i have converted image binary ease of computation

to achieve plan cycle through image horizontally analysing each row , detecting non-black pixels , storing them in 1xn matrix. @ end of image want concatenate matrix gives histogram of number of white pixels along each row , space between peaks (after threshold) indicate pixel spacing.
my code @ moment follows i'm limited in programming capability.
my_image =imread('image'); r=1:n c=1:n pixel=my_image(r,c); if pixel==1 counter=counter+1; end counter end counter=0; end
if understand problem correctly, want compute total number of white pixels per row , we'll store in array. code have works. doing though counting total amount of white pixels overall in image. code not describe desired behaviour exactly.
as such, let's go ahead , correctly. after this, can provide stem plot can use x-axis index row number of image while y-axis can used display total number of white pixels seen in image. pretty own observation, let's go ahead , plot this:
im = imread('http://i.imgur.com/lc8esac.png'); %// read in post imbinary = double(im2bw(im)); %// in case - convert binary, %// make double sum histogram = sum(imbinary,2); %// compute row-wise histograms stem(1:size(imbinary,1), histogram); %// plot histogram xlabel('row number'); ylabel('white pixel count'); grid; 
as can see image, agrees logic. you'll see approximately around rows 150 225, there spikes in histogram. if take difference between 225 , 150, give width (in pixels) of wire. however, logic fail in between approximately rows 300 400. you'll see wires on slant. if sum along rows, not able detect thickness of these wires way have few pixels per row white.
if want ignore these, can. can use diff compute pairwise neighbouring distances between elements. should difference non-zero, means have detected change. detect changes, threshold difference larger number, values want keep. in other words, this:
diffs = diff([0; histogram]); threshold = 100; %// define threshold here per request rows = find(diffs >= threshold) rows = 148 217 475 how diff works ith element in array x_i, output of diff y_i such that:
y_i = x_{i+1} - x_i therefore, notice in diff call, add 0 @ beginning of histogram before diff assume first row consists entirely of zeroes , count should 0. determine rows give me pixel count of 100 or more. user-defined threshold made up.
once this, can use diff command find final thickness in between wires:
thickness = diff(rows) thickness = 69 258 this says have 1 wire thickness of 69 pixels, while next wire after has thickness of 258 pixels.
this sensitive threshold , way binarize image, should enough started.
good luck!
Comments
Post a Comment