Effacer les filtres
Effacer les filtres

How can i convert black backgorund to white

3 vues (au cours des 30 derniers jours)
kalaivaani
kalaivaani le 20 Déc 2013
Commenté : kalaivaani le 22 Déc 2013
i want to eliminate or convert the black background to white except the centre image that i needed.this
<<
>>
2 images i had attached. the black intensity ranges as 0:45

Réponse acceptée

Image Analyst
Image Analyst le 20 Déc 2013
Modifié(e) : Image Analyst le 20 Déc 2013
Try this:
clc; % Clear the command window.
workspace; % Make sure the workspace panel is showing.
close all;
clear all;
format long g;
format compact;
fontSize = 20;
% Read in a color demo image.
folder = 'C:\Users\kalaivaani\Documents\Temporary';
baseFileName = 'bgrnd.JPG';
% 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);
axis on;
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);
% If background is less than 45, say it's background.
% Adjust the value as needed to achieve what you want.
thresholdValue = 45;
mask = redChannel <= thresholdValue & greenChannel <= thresholdValue & blueChannel <= thresholdValue;
% Display the mask image.
subplot(2, 2, 2);
imshow(mask);
title('Mask Image', 'FontSize', fontSize);
% Initialize the masked channels.
maskedRed = redChannel;
maskedGreen = greenChannel;
maskedBlue = blueChannel;
% Do the masking - make white where it was black.
maskedRed(mask) = 255;
maskedGreen(mask) = 255;
maskedBlue(mask) = 255;
% Recombine separate masked color channels into a single, true color RGB image.
maskedRgbImage = cat(3, maskedRed, maskedGreen, maskedBlue);
% Display the masked color image.
subplot(2, 2, 3);
imshow(maskedRgbImage);
title('Masked Color Image', 'FontSize', fontSize);
  2 commentaires
Image Analyst
Image Analyst le 21 Déc 2013
kalaivaani - what's going on? Did you ever check back to see if anyone took the effort to answer your question and help you?
kalaivaani
kalaivaani le 22 Déc 2013
thank you sir it's working i got it

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by