Getting rid of lots of thin black lines on an image
14 次查看(过去 30 天)
显示 更早的评论
I have several greyscale avi files. The camera that took these movies (or perhaps the software that transformed them into avi files) somehow got messed up, and there are several one pixel thick black (RGB values of [0 0 0]) lines running through the movies. I have already written a script that will take the movie and save each individual file as a bitmap, as well as a different script that will take the bitmaps and use them to create a new avi. What I need help with now is how to take the black pixels on the picture (there are very few pure black pixels on the screen that are not part of these lines, so I can select all [0 0 0] pixels without any real loss) and blur them out so they’re interpolated from the pixels directly above and beneath them. For example:
[115 115 115] [122 122 122] [97 97 97]
[0 0 0] [0 0 0] [0 0 0]
[119 119 119] [115 115 115] [101 101 101]
What I’m looking for is to change the middle row to the average of the row above and below it, so the middle row would become [117 117 117] [118 118 118] [99 99 99]. MATLAB probably isn’t the best tool for this job, but I don’t have admin rights on the computer I’m using for this, so I can’t install Image Magic. Any help from the MATLAB wizards out there would be greatly appreciated.
0 个评论
采纳的回答
Elad
2012-5-30
You can use, find() , something like this :
[r,c,v]=find(bmpimage==0);
for i=1:size(r)
bmpimage(r(i),c(i))=(bmpimage(r(i+1),c(i))+bmpimage(r(i-1),c(i)))/2;
end
0 个评论
更多回答(1 个)
Image Analyst
2012-5-31
One way is this demo I wrote to get rid of salt and pepper noise by doing a modified median filter. it finds black specks (gray level 0) and white specks (255) and replaces those with the median. If course if you had lots of black lines all together touching each other then the median could also be black, but then the interpolated line (like you suggested) would also be. You could enlarge the median window size from 3 by 3 to something larger if you still have zero value pixels in the output, or else just run the code again on the output image until all the black pixels go away. Just get rid of the color stuff - it's really easy to convert this code to grayscale.
clc; % Clear command window.
close all; % Close all figure windows except those created by imtool.
imtool close all; % Close all figure windows created by imtool.
workspace; % Make sure the workspace panel is showing.
fontSize = 15;
% Read in a standard MATLAB color demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'peppers.png';
fullFileName = fullfile(folder, baseFileName);
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows columns numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(3, 4, 1);
imshow(rgbImage);
title('Original color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Display the individual red, green, and blue color channels.
subplot(3, 4, 2);
imshow(redChannel);
title('Red Channel', 'FontSize', fontSize);
subplot(3, 4, 3);
imshow(greenChannel);
title('Green Channel', 'FontSize', fontSize);
subplot(3, 4, 4);
imshow(blueChannel);
title('Blue Channel', 'FontSize', fontSize);
% Generate a noisy image. This has salt and pepper noise independently on
% each color channel so the noise may be colored.
noisyRGB = imnoise(rgbImage,'salt & pepper', 0.05);
subplot(3, 4, 5);
imshow(noisyRGB);
title('Image with Salt and Pepper Noise', 'FontSize', fontSize);
% Extract the individual red, green, and blue color channels.
redChannel = noisyRGB(:, :, 1);
greenChannel = noisyRGB(:, :, 2);
blueChannel = noisyRGB(:, :, 3);
% Display the noisy channel images.
subplot(3, 4, 6);
imshow(redChannel);
title('Noisy Red Channel', 'FontSize', fontSize);
subplot(3, 4, 7);
imshow(greenChannel);
title('Noisy Green Channel', 'FontSize', fontSize);
subplot(3, 4, 8);
imshow(blueChannel);
title('Noisy Blue Channel', 'FontSize', fontSize);
% Median Filter the channels:
redMF = medfilt2(redChannel, [3 3]);
greenMF = medfilt2(greenChannel, [3 3]);
blueMF = medfilt2(blueChannel, [3 3]);
% Find the noise in the red.
noiseImage = (redChannel == 0 | redChannel == 255);
% Get rid of the noise in the red by replacing with median.
noiseFreeRed = redChannel;
noiseFreeRed(noiseImage) = redMF(noiseImage);
% Find the noise in the green.
noiseImage = (greenChannel == 0 | greenChannel == 255);
% Get rid of the noise in the green by replacing with median.
noiseFreeGreen = greenChannel;
noiseFreeGreen(noiseImage) = greenMF(noiseImage);
% Find the noise in the blue.
noiseImage = (blueChannel == 0 | blueChannel == 255);
% Get rid of the noise in the blue by replacing with median.
noiseFreeBlue = blueChannel;
noiseFreeBlue(noiseImage) = blueMF(noiseImage);
% Reconstruct the noise free RGB image
rgbFixed = cat(3, noiseFreeRed, noiseFreeGreen, noiseFreeBlue);
subplot(3, 4, 9);
imshow(rgbFixed);
title('Restored Image', 'FontSize', fontSize);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Adaptive Filters 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!