how can i find the displacement in pixels for the 1st, 3rd and 5th squares in the picture

조회 수: 3 (최근 30일)
the bridge in the picture was loaded 4 times and a picture was taken after each load, im trying to find the displacement in pixels for the 1st, 3rd and 5th squares in the picture. the 2nd and 4th squares are fixed. i have the displacement readings from the dial gauges but i also need the pixel displacement. im not familiar with image processing techniques, any suggestion would be appreciated.

채택된 답변

Thorsten
Thorsten 2016년 10월 10일
편집: Thorsten 2016년 10월 12일
% number here found by visual inspection
I = im2double(imread('1.JPG'));
index_center = size(I,2)/2+100:size(I,2)/2+250;
offset = [-1910 0 1854]; % left, center, right
Noffsets = numel(offset);
Nimages = 5;
% preallocate result
dx = zeros(Nimages, Noffsets);
dy = zeros(Nimages, Noffsets);
for o = 1:3
for im = 1:Nimages
I = im2double(imread([int2str(im) '.JPG']));
% crop central part of image with the black square
Ic = I((1610:1750),index_center + offset(o));
subplot(1,3,2), imshow(Ic)
title({['Square from image ' int2str(im) ], 'to be matched to S1.'})
drawnow
if im == 1 % just the black square
S = Ic;
s = 40;
S = S(s:end-s, s:end-s);
szS = size(S);
% find square of
subplot(1,3,1), imshow(S)
title('S1: square from image 1')
drawnow
end
szIc = size(Ic);
sz = szIc - szS;
R = nan(sz(1), sz(2));
% find best match; simple brute force method
for i = 1:sz(1)
for j = 1:sz(2)
R(i,j) = sum(sum(abs(S - Ic(i:i+szS(1)-1, j:j+szS(2)-1))));
end;
end
[dy(im,o), dx(im,o)] = ind2sub(size(R),find(R == min(R(:))));
end
end
% relative displacement: subtract dy of image 1
dy_rel = bsxfun(@minus, dy(2:end,:), dy(1,:));
subplot(1,3,3)
plot(2:5, dy_rel, 'o-')
axis([2 5 0 12])
xlabel('Image #')
ylabel('Offset in pixels')
box off
legend({'left', 'center', 'right'})
legend boxoff
  댓글 수: 4
ZERO
ZERO 2016년 10월 13일
it runs perfectly , thank you.
where did you get 100 and 250 from. what do they represent? index_center = size(I,2)/2+100:size(I,2)/2+250;
also how did you get the offset values? offset = [-1910 0 1854]; % left, center, right

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

KSSV
KSSV 2016년 10월 10일
You have to read the image first using imread, specify the location where you want pixels.
Pseuodcode:
RGB = imread('myimage'); % read the color values of the image
% specify the row and column position where you want to extract pixels
c = [12 146 410];
r = [104 156 129];
pixels = impixel(RGB,c,r) ; % get pixels at the given locations
  댓글 수: 5
Image Analyst
Image Analyst 2016년 10월 11일
I told you how to get the centroid of the square rings in my answer. Maybe if I have time later I can do it for you, if you can't.
ZERO
ZERO 2016년 10월 13일
thank you for trying to answer, i wouldn't have asked this question if i knew what i need to do.

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2016년 10월 10일
This is pretty easy.
  1. First I'd mask out the vertical lanes where your reference squares are, just to make sure there's no clutter anywhere that could be confused with the squares.
  2. Then threshold. This could get the white squares and the white sticks so
  3. label and call regionprops and look at the bounding box width and height and throw out (with ismember) any blobs where the width to height ratio is not close to 1.
  4. Then call regionprops again with the "good" squares getting the centroids. You're basically done now.
See my Image Segmentation Tutorial for a demo of this: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by