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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/160431/image.png)
댓글 수: 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에서 Read, Write, and Modify Image에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!