Azzera filtri
Azzera filtri

how to replace the color of the pixel with its neighborhood darkest pixel???

1 visualizzazione (ultimi 30 giorni)
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.

Risposte (1)

Image Analyst
Image Analyst il 7 Apr 2014
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);

Categorie

Scopri di più su Read, Write, and Modify Image in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by