How can I compare Images and choose the best based on which has the least white spots?
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I want to ask a question about a project.
I have many different images, but in some of them there are some white spots. I want somehow to check in these pics if there are many of them and if so to reject these images. To make it clear, I want to create an algorithm that will check those images(compare them) and choose the best. The best image will be the image that has the fewest white spots.
For example I have these 3 images :
As you can see the 3rd image is the image with the fewer white spots.
So, in my algorithm I want somehow to check (maybe in a loop) images like this and to come up with the pic with the fewer white spots.
Any suggestions of how I can do this?
Thank you in advance!
2 个评论
DGM
2021-3-21
I suppose it depends on how easily the white defects can be separated from the background, and what exactly we mean by "least".
I'll assume that we can reliably detect white defects using some combination of contrast adjustment and thresholding to yield a logical map describing the defects alone.
From there, we can either count the number of spots (i.e. if 'least' means 'fewest number of spots'), or we can use the sum or average of the map (i.e. if 'least' means 'least amount of the image').
Counting the spots can be done using bwlabel() and unique(), though I'm sure there are lots of different ways to approach this. You might want to browse the IPT docs on image segmentation if that's the route you want to take.
回答(1 个)
DGM
2021-3-21
编辑:DGM
2021-3-21
Technical image processing isn't exactly my background, but I'll take a shot at this. If we want to find the image with the fewest number of white groups:
% read images and build a multiframe array
% this can be done in various ways.
% i'd normally use imstacker() and mimread() from the MIMT, but this works
% the only reason i'm making a multiframe array is so that i can index
% through it in a simple loop.
A=rgb2gray(imread('train1.jpg'));
B=rgb2gray(imread('train2.jpg'));
C=rgb2gray(imread('train3.jpg'));
alltrainpix=cat(4,A,B,C);
clear A B C
numframes=size(alltrainpix,4);
% we could probably do some pre-processing before thresholding, but i'm not going to.
% how we pick a threshold depends on what we expect. I'm just picking something arbitrary.
whitemap=(alltrainpix>254);
% at this point, we have to ask whether the smallest isolated groups should count
% if they don't, they can be removed using morphological tools like imopen() or bwareaopen()
% otherwise, we can count the number of connected groups in each frame of the thresholded image
groupcounts=zeros([numframes 1]);
for f=1:numframes
L=bwlabel(whitemap(:,:,1,f),8);
groupcounts(f)=numel(unique(L));
end
% observe the number of connected groups per frame
groupcounts
which returns
groupcounts =
232
198
60
That said, I'm not so sure that a metric other than object count wouldn't better describe the image quality. Someone else may be able to offer a more appropriate suggestion.
2 个评论
Image Analyst
2021-3-21
That's fine for a start. If it doesn't work because the "white spots" vary in brightness depending on where in the image they are, then you'll have to do a locally adaptive algorithm and suddenly the situation just got a whole lot harder.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!