Re: grouping pixels and counting groups
- From: "Image Analyst" <imageanalyst@xxxxxxxxxxxxxx>
- Date: Wed, 4 Mar 2009 20:24:01 +0000 (UTC)
"Evan " <eetrocnative@xxxxxxxxx> wrote in message <gomn6r$c4o$1@xxxxxxxxxxxxxxxxxx>...
Jomar Bueyes <jomarbueyes@xxxxxxxxxxx> wrote in message <b58e5a77-f5ac-4299-810d-327a71a6c589@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>...
On Mar 4, 12:56=A0pm, "Evan " <eetrocnat...@xxxxxxxxx> wrote:
Hello.defective pixels, and then searches for and counts groups of defective pixe=
I am trying to write a function which takes an image as its input, finds =
ls. The image is 480x752 pixels and is saved as a bitmap image. Defective p=
ixels are irregularities such as random white dots in an otherwise black im=
age. Groups are defective pixels adjacent to each other.
n as a '1' in a separate matrix which is initialized as all zeros.
I already wrote code which finds defective pixels and records the locatio=
Does anyone have any idea as to how I should proceed?
Hi,
One way to identify bad pixels is to look at the neighborhood of each
pixel (say a 5x5 or larger neighborhood) and calculate the mean and
std. deviation of the pixels in the neighborhood. If the pixel of
interest differs from the mean of the neighborhood by more than an
arbitrarily threshold (e.g. 2.5*std. dev), the pixel is likely to be
bad. The method is rather ad hoc, but we have successfully used it to
identify bad pixels of a CCD camera after an image has been collected
w/o the corresponding calibration image.
HTH
Jomar
Thanks for your reply. I actually use an 11x11 "box" around each pixel of interest to determine if it is sufficiently different enough from its neighbors to be labeled as bright/very bright or dark/very dark. Defective pixel locations are stored as a '1' in secondary matrices (darkcluster and brightcluster). My question is about the best way to find groups of defective pixels.
Currently, I am using my secondary matrices, to hold the location of defective pixels for me. I take each one as a vector and compare individual defect locations to their neighbors of higher index value (see the code slice below) and only increment a counter if a 1 is next to a 1. Whenever a 1 is next to another 1, both become 2s, which simply mean that they have already been counted once and won't be counted again. I doublecheck that darkcluster(n) == 1 inside of the nested if loop because once the code enters the first check, the value of darkcluster(n) gets changed and I want to prevent the same group from counting more than once.
**darkcluster is already loaded with a 1 in every defective pixel location**
for n = 481:360480; % skip the first and last columns
if(not(mod(n,480) == 1) && not(mod(n,480) == 0)) % skip rows 1 and 480
if(darkcluster(n) == 1) % unmodified since it was determined to be defective
if(darkcluster(n+1) == 1)
if(darkcluster(n) == 1) % to make sure I dont count the same group 2x
darkclustercount = darkclustercount + 1;
end
darkcluster(n) = 2;
darkcluster(n+1) = 2;
end
if(darkcluster(n+479) == 1)
if(darkcluster(n) == 1)
darkclustercount = darkclustercount + 1;
end
darkcluster(n) = 2;
darkcluster(n+479) = 2;
end
if(darkcluster(n+480) == 1) .....
.....
I think it may just be my brute force method, but the code takes almost 5 minutes to run. Does that seem reasonable, considering that I have to make so many millions of calculations to find the defects and then search for groups?
---------------------------------------------------------------------------------
Evan:
You posted this while I was composing my first reponse. What you are trying to do is your own labeling. Just dump all that code above, and call bwlabel(). It will do the job for you in a fraction of a second. You need the image processing toolbox to get the bwlabel() function.
Good luck,
ImageAnalyst
.
- Follow-Ups:
- Re: grouping pixels and counting groups
- From: Evan
- Re: grouping pixels and counting groups
- References:
- grouping pixels and counting groups
- From: Evan
- Re: grouping pixels and counting groups
- From: Jomar Bueyes
- Re: grouping pixels and counting groups
- From: Evan
- grouping pixels and counting groups
- Prev by Date: Re: using the if function with a difference
- Next by Date: Re: Very weird resolution issue. Bug ????? Seriously !!
- Previous by thread: Re: grouping pixels and counting groups
- Next by thread: Re: grouping pixels and counting groups
- Index(es):
Relevant Pages
|