Masking 3 dead pixels on a camera

3 visualizaciones (últimos 30 días)
Villanova
Villanova el 19 de Feb. de 2014
Comentada: Image Analyst el 24 de Feb. de 2014
Hello. I am working on a robotic project with a camera to capture images of blue,red,green LEDs. Apparently, the camera has 3 dead pixels. When there is no LED present, using the code below, camera detects three pixels (one red one blue one green) which are the dead pixels on the camera. I was wondering how I could mask these 3 pixels. Here is the output: [rrpts crpts rgpts_t cgpts_t rbpts cbpts] = [367 537 616 888 582 350] in which each consecutive pair is a x-y location of each dead pixel (they are the pairs I want to mask). My code is also shown below. Thank you.
Clear all
Close all;
Global rthr gthr bthr
rthr = 60;
bthr = 60;
gthr = 60;
delete(imaqfind);
vid = videoinput('dcam');
vid.ReturnedColorSpace ='bayer';
vid.BayerSensorAlignment ='rggb';
vid.ROIPosition = [60 40 960 720];
vid.FramesPerTrigger = 1;
%triggerconfig(vid,'manual')
% vid.TriggerRepeat = Inf;
src = getselectedsource(vid);
src.Gain = 500;
start(vid)
%preview(vid)
[img time] = getdata(vid);
[rrpts crpts rgpts_t cgpts_t rbpts cbpts] = gsearch_rgb(img)
figure (1)
imshow(img)
%imshow(rgbImage)
stop(vid);

Respuesta aceptada

Image Analyst
Image Analyst el 19 de Feb. de 2014
I'd take those locations and get the mean in a 3x3 window around them and replace them with the mean. Like
subImage = redChannel(crpts-1: crpts+1, rrpts -1 : rrpts + 1);
meanRed = mean2(subImage);
redChannel(crpts, rrpts) = uint8(meanRed);
Same for the other color channels. And make sure they're x-y locations, because that's what I assumed because that's what you said, and not row-column locations in which case you'll need to swap the indexes.

Más respuestas (2)

Villanova
Villanova el 24 de Feb. de 2014
Editada: Villanova el 24 de Feb. de 2014
Thank you for your help Image Analyst. You were right; those values were row-column values. What I ened up doing was to creat row-column bad cell arrays in order to get rid of them. I have one more question. We have a function as I've attached which looks for red, green and blue LEDs on a robotic platform. Are you aware of a logic that does so perhaps using blob analysis? Or what is the best logic to do so (Do you know if there is a simillar source code). Thanks
% RGB pixel group search
function [rrpts crpts rgpts cgpts rbpts cbpts] = gsearch_rgb_new(img)
global rthr gthr bthr
%global rr cr rg cg rb cb
dthr = 35;
bad_cells_r = [363 367 533 537 578 582];
bad_cells_c = [612 616 884 888 346 350];
for bc=1:6
for col=1:3
img(bad_cells_r(bc), bad_cells_c(bc), col) = 0;
end
end
[rr cr] = find(img(:,:,1) >= rthr)
[rg cg] = find(img(:,:,2) >= gthr)
[rb cb] = find(img(:,:,3) >= bthr)
% rrpts = rr;
% crpts = cr;
% rgpts = rg;
% cgpts = cg;
% rbpts = rb;
% cbpts = cb;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rcell = {rr rg rb};
ccell = {cr cg cb};
for i = 1:3 % 1: red, 2: green, 3: blue
rpts = []; cpts = []; % initialze point vectors for the current color
k = 0; % initialize point counter
r = cell2mat(rcell(i));
c = cell2mat(ccell(i));
exit_flag = 1;
while exit_flag % find all groups of current color
j1 = 0; % counter for pixels in current group
j2 = 0; % counter for pixels excluded from current group
rtemp = []; ctemp = []; rkeep = []; ckeep = []; % initialize temporary pixel vectors
for m = 1:1:length(c) % loop for all found pixels
if m ~= 1
delta = min(abs(c(m)-ctemp) + abs(r(m)-rtemp));
else
delta = 0;
end
%if (delta < dthr) || (m == 1) % store grouped pixels
if (delta < dthr) % store grouped pixels
j1 = j1 + 1;
rtemp(j1) = r(m);
ctemp(j1) = c(m);
else % store excluded pixels
j2 = j2 + 1;
rkeep(j2) = r(m);
ckeep(j2) = c(m);
end
end
rcent = mean(rtemp); % find center of group
ccent = mean(ctemp);
ind1 = round(rcent); % approximate center pixle
ind2 = round(ccent);
% sze = ceil(sqrt(j1)/2); % sets size of square neighborhood
sze = ceil(sqrt(j1)/2)+1; % sets size of square neighborhood
% This is necessary because small points could be missed if
% the neighborhood is too much larger than the actual led
% Neighborhoods are always at least 3x3
sqr = -sze:sze;
rsqr = img(ind1+sqr,ind2+sqr,1);
gsqr = img(ind1+sqr,ind2+sqr,2);
bsqr = img(ind1+sqr,ind2+sqr,3);
isumi = [sum(sum(rsqr)) sum(sum(gsqr)) sum(sum(bsqr))];
[val ind] = max(isumi);
if ind == i % found group is the current color
k = k + 1;
rpts(k) = rcent;
cpts(k) = ccent;
end
if j2 > 0 % ungrouped pixels remain
r = rkeep;
c = ckeep;
else % exit
exit_flag = 0;
end
end % search while loop
rpts_cell(i) = {rpts};
cpts_cell(i) = {cpts};
end % color for loop
rrpts = cell2mat(rpts_cell(1));
crpts = cell2mat(cpts_cell(1));
rgpts = cell2mat(rpts_cell(2));
cgpts = cell2mat(cpts_cell(2));
rbpts = cell2mat(rpts_cell(3));
cbpts = cell2mat(cpts_cell(3));
  1 comentario
Image Analyst
Image Analyst el 24 de Feb. de 2014
I have several demos for detecting colors in my File Exchange. They all do basically the same thing but in different ways, different color spaces. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 You should examine your 3D color gamut first to decide which color space is best. You can use the 3D Color Inspector plugin for ImageJ because MATLAB does not have this capability (yet). http://rsb.info.nih.gov/ij/plugins/color-inspector.html

Iniciar sesión para comentar.


Sean de Wolski
Sean de Wolski el 24 de Feb. de 2014

Categorías

Más información sobre MATLAB Support Package for USB Webcams en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by