how can i find the displacement in pixels for the 1st, 3rd and 5th squares in the picture
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
ZERO
el 10 de Oct. de 2016
Comentada: Thorsten
el 17 de Oct. de 2016
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.
0 comentarios
Respuesta aceptada
Thorsten
el 10 de Oct. de 2016
Editada: Thorsten
el 12 de Oct. de 2016
% 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 comentarios
Más respuestas (2)
KSSV
el 10 de Oct. de 2016
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 comentarios
Image Analyst
el 11 de Oct. de 2016
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.
Image Analyst
el 10 de Oct. de 2016
This is pretty easy.
- 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.
- Then threshold. This could get the white squares and the white sticks so
- 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.
- 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
0 comentarios
Ver también
Categorías
Más información sobre Image Processing Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!