How can I compare Images and choose the best based on which has the least white spots?
1 view (last 30 days)
Show older comments
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 Comments
DGM
on 21 Mar 2021
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.
Answers (1)
DGM
on 21 Mar 2021
Edited: DGM
on 21 Mar 2021
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 Comments
Image Analyst
on 21 Mar 2021
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.
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!