Difference (mistake) between two images
조회 수: 12(최근 30일)
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.
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;
% 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, ...
% 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)
Image Analyst 2022년 11월 13일
There are probably lots of ways to solve this but I'd start like this.
- Threshold to find the large two black rectangles on the right side of the jig.
- use regionprops to get the two centroids, then find the angle between them
- use imrotate to make them level.
- then find the spots again and use imtranslate to put the upper right dark rectangle at some known location. Do that for both images.
- Then use imabsdiff to subtract the two images.
- Threshold to find the difference.
- Call imclearborder to get rid of any differences touching the edge of the image.
- Call imfill to fill any holes.
- Call bwareafilt to get only blobs in a certain known area range.
- 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.