Difference (mistake) between two images

조회 수: 12(최근 30일)
Audrius Bieliunas
Audrius Bieliunas 2022년 11월 13일
댓글: Audrius Bieliunas 2022년 12월 23일
Hello, I need help with a Master project. I need rectangle human mistake, in connector seals.
In picture 1.jpg, I have a connector with 17 white seals, this is model1.
In picture 2.jpg, I have a connector with 16 white seals, this is model2. (MODEL WITH MISTAKE, 1 missing white seal)
In autocad drawing i want to color or choose what model will be, somehow automatic combine (register) it with the model2 or new image with mistake, and rectangle that place, like in the last image. All images will be created from same height and angle.
so long i can to bwlabel the drawing(image) and choose what circles i want to paint.
rectangled mistake.
I cant use imregcorr to register autocad drawing with model1 because, its working just on rgb image, and i cant bwlabel the autocaddrawing without imbinarizing it. So thx for your time and waiting for answer.

채택된 답변

DGM 2022년 11월 14일
This isn't exactly production ready, but it's a rough example. This uses CVT tools to do the registration estimation. I don't know how robust this will be with the given settings in the registration function. I don't have CVT and I don't have but the one image to try it on.
% get the images, discard color
good = imread('good.jpg');
bad = imread('mistake.jpg');
good = rgb2gray(good);
bad = rgb2gray(bad);
% detect the plugs
goodplug = imfill(imbinarize(good),'holes');
badplug = imfill(imbinarize(bad),'holes');
goodplug = bwareaopen(goodplug,100);
badplug = bwareaopen(badplug,100);
% remove the plugs from both images
goodnoplug = good;
goodnoplug(goodplug) = 0;
badnoplug = bad;
badnoplug(badplug) = 0;
montage({goodnoplug badnoplug})
% attempt to register the images (requires CVT)
movreg = registerImages_connector(badnoplug,goodnoplug);
% use the image registration to register the plug masks
badplugadj = imwarp(badplug,movreg.InitialRefObj,movreg.Transformation, ...
'OutputView',movreg.ResultRefObj,'SmoothEdges', true);
montage({goodplug badplugadj})
% split the blobs in the good plug mask
goodplug = bwdist(~goodplug)>=5; % adjust radius if necessary
% find blob centroids as linear indices
S = regionprops(goodplug,'centroid');
plugidx = round(vertcat(S.Centroid));
plugidx = sub2ind(size(goodplug),plugidx(:,2),plugidx(:,1));
% check those locations in the registered image under test
plugismissing = ~badplugadj(plugidx)
plugismissing = 17×1 logical array
0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
  댓글 수: 20
Audrius Bieliunas
Audrius Bieliunas 2022년 12월 23일
thank u sir, that was what i look for. U save the day.

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

추가 답변(1개)

Image Analyst
Image Analyst 2022년 11월 13일
There are probably lots of ways to solve this but I'd start like this.
  1. Threshold to find the large two black rectangles on the right side of the jig.
  2. use regionprops to get the two centroids, then find the angle between them
  3. use imrotate to make them level.
  4. then find the spots again and use imtranslate to put the upper right dark rectangle at some known location. Do that for both images.
  5. Then use imabsdiff to subtract the two images.
  6. Threshold to find the difference.
  7. Call imclearborder to get rid of any differences touching the edge of the image.
  8. Call imfill to fill any holes.
  9. Call bwareafilt to get only blobs in a certain known area range.
  10. Call bwlabel or regionprops to count and locate the missing or extra white blob.
As you can see, pretty easy, it's just that there are a lot of simple steps.
Write back if you can't figure it out.

Community Treasure Hunt

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

Start Hunting!

Translated by