clear;clc;close all;
%-----------------------------Input---------------------------------------%
%Coordinate in the photo
co_x_b = 90;
co_y_b = 120;
%Tolerance for color
tol = 3;
%----------------------------Code-----------------------------------------%
a = imread('birefringence.jpg');
b = imread('birefringence2.jpg');
[x_a y_a,~]= size(a);
[x_b y_b,~]= size(b);
r_b = b(co_x_b,co_y_b,1);
g_b = b(co_x_b,co_y_b,2);
b_b = b(co_x_b,co_y_b,3);
%Plot the photo that contains the target spot
figure(1);image(b);axis equal tight; hold on
plot(co_y_b,co_x_b,'b.','markersize',30)
%Plot the color spot on the photo
figure(2);
c(1,1,1)=r_b;
c(1,1,2)=g_b;
c(1,1,3)=b_b;
image(c);
%Plot the reference photo
figure(3); image(a); axis equal tight; hold on
%
found_pixel = false;
for j = 1:y_a
for i = 1:x_a
r_a = a(i,j,1);
g_a = a(i,j,2);
b_a = a(i,j,3);
if ( ((r_b < r_a+tol) && (r_b > r_a-tol)) ...
&& ((g_b < g_a+tol) && (g_b > g_a-tol)) ...
&& ((b_b < b_a+tol) && (b_b > b_a-tol)) ...
)
fprintf('Found coordinate: x= %i y=%i \n',i,j)
co_x = i;
co_y = j;
found_pixel=true;
plot(co_y,co_x,'b.','markersize',30)
end
end
end
if ~found_pixel
fprintf('No matching spots found. Please increase the tolerance. \n')
end
ใครมีความรู้เกี่ยวกับโปรแกรม matlab ช่วยเข้ามาอธิบายความหมายของคำสั่งแต่ละบรรทัดหน่อยครับ ขอละเอียด
%-----------------------------Input---------------------------------------%
%Coordinate in the photo
co_x_b = 90;
co_y_b = 120;
%Tolerance for color
tol = 3;
%----------------------------Code-----------------------------------------%
a = imread('birefringence.jpg');
b = imread('birefringence2.jpg');
[x_a y_a,~]= size(a);
[x_b y_b,~]= size(b);
r_b = b(co_x_b,co_y_b,1);
g_b = b(co_x_b,co_y_b,2);
b_b = b(co_x_b,co_y_b,3);
%Plot the photo that contains the target spot
figure(1);image(b);axis equal tight; hold on
plot(co_y_b,co_x_b,'b.','markersize',30)
%Plot the color spot on the photo
figure(2);
c(1,1,1)=r_b;
c(1,1,2)=g_b;
c(1,1,3)=b_b;
image(c);
%Plot the reference photo
figure(3); image(a); axis equal tight; hold on
%
found_pixel = false;
for j = 1:y_a
for i = 1:x_a
r_a = a(i,j,1);
g_a = a(i,j,2);
b_a = a(i,j,3);
if ( ((r_b < r_a+tol) && (r_b > r_a-tol)) ...
&& ((g_b < g_a+tol) && (g_b > g_a-tol)) ...
&& ((b_b < b_a+tol) && (b_b > b_a-tol)) ...
)
fprintf('Found coordinate: x= %i y=%i \n',i,j)
co_x = i;
co_y = j;
found_pixel=true;
plot(co_y,co_x,'b.','markersize',30)
end
end
end
if ~found_pixel
fprintf('No matching spots found. Please increase the tolerance. \n')
end