how to replace the color of the pixel with its neighborhood darkest pixel???
2 次查看(过去 30 天)
显示 更早的评论
My images are not uniform.Every time image background color is going to be change.Here is the image.From this image i want to replace Google with orange color.
0 个评论
回答(1 个)
Image Analyst
2014-4-7
Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 22;
% Read in a standard MATLAB color demo image.
folder = 'D:\Temporary Stuff';
baseFileName = '4545.png';
% 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(2, 2, 1);
imshow(rgbImage);
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
mask = redChannel < 200; % Letters
% Enlarge it a bit
mask = imdilate(mask, true(3));
subplot(2, 2, 2);
imshow(mask);
title('Mask for Letters', 'FontSize', fontSize);
% Get the mean RGB values
meanR = mean2(redChannel(~mask));
meanG = mean2(greenChannel(~mask));
meanB = mean2(blueChannel(~mask));
% Fill in letters with background.
redChannel(mask) = meanR;
greenChannel(mask) = meanG;
blueChannel(mask) = meanB;
% Recombine separate color channels into a single, true color RGB image.
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
subplot(2, 2, 3);
imshow(rgbImage);
title('Letters are gone!', 'FontSize', fontSize);
0 个评论
另请参阅
类别
在 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!