give colour to a particular pixel of an image

2 views (last 30 days)
hy there,,, i need help to solve my problem about give colour to a particular pixel of an image,,,
i've done thresholding at my image,, after that i want to find the coordinates anywhere that is worth 1 on taht image. Having obtained the coordinates, original RGB image was split into three matrix of matrix R, G and B is the matrix components RGB image forming. After that step, The next is to give a value of 255 on that coordinates for the matrix R, the value 0 the coordinates skin on the matrix G and value 0 on the coordinates on the matrix B, so that in the original image (RGB) area that i want to colouring will be red.
how can i do that??? need help please,, is there anybody have code for this problem?? thanks. Gbu

Accepted Answer

Walter Roberson
Walter Roberson on 15 Aug 2011
If you have already split your original matrix in to R, G, and B, then if ImgT is the threshholded binary image, you would simply use
ColoredImage = R .* ImgT;
ColoredImage(1,1,3) = 0;
  7 Comments
Walter Roberson
Walter Roberson on 18 Aug 2011
Sorry, I'm still having trouble understanding the question, so this will have to wait until I have some spare time. (If someone else understands the back-and-forth of the question, feel free to jump in with a solution!)
Note: merely saying that something is "urgent" doesn't work. If it really is Urgent, have one of your ambassadors talk to the Canadian Ambassador to your country and make a presentation as to why it is in the interest of both of our countries that I be temporary taken off of my regular work to solve your technical difficulty. The Canadian Ambassadors are trained in how to contact me.
Image Analyst
Image Analyst on 18 Aug 2011
He posted my code that I gave him or someone here or in the newsgroup. I ended by saying that the extension to RGB images is straightforward - just extract the colors and do the same thing this code does: mask the arrays and recombine. Apparently it's far more challenging than I would have thought (since this is his third original Answers post on the same topic). So I guess it's up to me to make the adaptation. Look in an upcoming answer (rather than this comment).

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 18 Aug 2011
OK, here's your new code. I adapted it from my code in your comment above. Copy, paste, run, then stand back and admire. :-) It looks longer and harder than it really is - just take it one commented step at a time. ImageAnalyst
% Demo to turn white parts of an image red.
% By ImageAnalyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 15;
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
% Read in a standard MATLAB gray scale 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 = 1.
[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'));
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Display the individual 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);
% Create a binary mask.
mask = redChannel > 160 & greenChannel > 150 & blueChannel > 100;
subplot(3, 4, 5);
imshow(mask);
title('Mask', 'FontSize', fontSize);
% Apply masks to the channels. Make the mask pixels red.
maskedRed = redChannel;
maskedGreen = greenChannel;
maskedBlue = blueChannel;
maskedRed(mask) = 255;
maskedGreen(mask) = 0;
maskedBlue(mask) = 0;
% Display the individual color channels
subplot(3, 4, 6);
imshow(maskedRed);
title('Masked Red Channel', 'FontSize', fontSize);
subplot(3, 4, 7);
imshow(maskedGreen);
title('Masked Green Channel', 'FontSize', fontSize);
subplot(3, 4, 8);
imshow(maskedBlue);
title('Masked Blue Channel', 'FontSize', fontSize);
% Combine the new color channels into our new RGB image.
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
% Create the RGB image.
coloredImage = cat(3, maskedRed, maskedGreen, maskedBlue);
% Display the new, colored image.
subplot(3,4,10);
imshow(coloredImage, []);
title('New Colored Image', 'FontSize', fontSize);
  5 Comments
UNHAS HASANUDDIN
UNHAS HASANUDDIN on 6 Sep 2011
i want to say a lot of thank you for Mr.ImageAnalyst and Mr.Walter Roberson. Now it works and i've got what i want with little modification with that code above. thank you so much.
now i have another problem,,
I have some satellite image that I downloaded from USGS. I want to doing cropping to the part of that image that unnecessary and take just the areas that I need. I want to ask how to cut the unnecessary part of that image and leaving only the parts that I need? and how to keep cropping I did, have same result for every image? because I need the same cropping area for each image.
can you help me??
thanks for all
God bless you
Walter Roberson
Walter Roberson on 6 Sep 2011
Please do not post unrelated questions in an existing topic; most people will not notice them.
You posted your cropping question as a new topic already, and I answered there.

Sign in to comment.

Categories

Find more on Verification, Validation, and Test in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!