subtract rgb pixel value of one image from another only in range of difference of 20 pixels. If difference between the rgb pixel value is less than 20 pixels then subtract rgb pixel. ifnot less than 20 pixels then make the value of that pixel zero. i

2 vues (au cours des 30 derniers jours)
So I am accepting a bare pcb and a mounted pcb image. I have been asked to subtract the bare pcb image from mounted pcb only if:
The RGB pixel value at same co-ordinate on both images does not have a difference of more than 20.
for eg:
at position (x1,y1) the rgb pixel value is (a1,b1,c1) & at position (x2,y2) the rgb pixel value is (a2,b2,c2)
if a2>= a1 + 20 or a1 - 20
b2>= b1 + 20 or b1 - 20
c2>= c1 + 20 or c1 - 20
if any of the condition is satisfied then do subtraction otherwise r=g=b=0 (make pixel black)
I have written the following code :
%Step 2: Pixel mapping
I=imread('C:\Users\crop_output2.jpg');
J=imread('C:\Users\crop_output1.jpg');
[M , N]= size(I);
[O , P]= size(J);
imshow(I);
imshow(J);
% Z = zeros(sz, 'uint8');
% K = zeros(si, 'uint8');
for i= 1:M
for j = 1:N
K(i, j) = J(i, j);
end
end
for i= 1:M
for j = 1:N
r= I(i,j,1) - J(i,j,1);
g= I(i,j,2) - J(i,j,2);
b= I(i,j,3) - J(i,j,3);
if((r>=-10 && r<=10) || (g>=-10 && g<=10) || (b>=-10 && b<=10))
then r=g=b=0;
else Z(i,j)= I(i,j)-J(i,j);
disp(Z);
end
end
end
I am not being able to access the position and get rgb value of pixel. Any kind of help will be appreciated

Réponses (1)

Walter Roberson
Walter Roberson le 18 Fév 2017
difference = double(I) - double(J);
mask = any(abs(difference) > 20, 3);
difference(mask(:,:,[1 1 1])) = 0;
differenceImage = cast(difference, class(I));

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by