Find and plot the variation of R, G, and B values of the image

조회 수: 1 (최근 30일)
Garrett Nagy
Garrett Nagy 2015년 9월 30일
댓글: Walter Roberson 2015년 10월 4일
Looking for help on finding and plotting the values of R, G, and B of the attached image. Also to find pixel locations of the dark lines and the wavelength of the dark lines. I am new to MatLab and could use a little help. Thank you in advance.
  댓글 수: 6
Walter Roberson
Walter Roberson 2015년 10월 2일
Okay, but how would you like to "plot" the values of R, G, and B ?
Garrett Nagy
Garrett Nagy 2015년 10월 4일
Each color on its own graph along the x direction. So the amount of color vs frequency probably

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2015년 9월 30일
RGB = imread('YourImage.tif');
Red = RGB(:,:,1);
histogram(Red(:))
  댓글 수: 2
Garrett Nagy
Garrett Nagy 2015년 10월 4일
i got the red to work but i cannot do the same thing for green or blue, i get an error that says index exceeds matrix dimensions. I tried to do BLUE = RGB(:,:,3) and GREEN = RGB(:,:,2) and came up with that error above.
Walter Roberson
Walter Roberson 2015년 10월 4일
It sounds like your tif might be pseudocolor
[img, map] = imread('YourImage.tif');
and check to see if img comes out 2 dimensional and map comes out non-empty. If so then you can use ind2rgb() to convert it to RGB

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2015년 10월 4일
Like I said before, you can't get wavelength from an RGB color. But if what you really want is a plot of the red signal, green signal, and blue signal as a function of distance along your x axis, then you can do that with this code:
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 = 20;
% Open an image.
% Browse for the image file.
[baseFileName, folder] = uigetfile('*.jpg', 'Specify a JPG image file');
fullImageFileName = fullfile(folder, baseFileName);
if folder == 0
return;
end
% Read in image into an array.
[rgbImage, storedColorMap] = imread(fullImageFileName);
[rows, columns, numberOfColorBands] = size(rgbImage)
% If it's monochrome (indexed), convert it to color.
if numberOfColorBands < 3
uiwait(warndlg('It must be a color image'));
end
% Display the original image.
subplot(2, 1, 1);
imshow(rgbImage);
title('RGB Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis on;
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
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);
subplot(2, 1, 2);
% Plot the red signal
plot(redChannel(1, :), 'r', 'LineWidth', 2);
grid on;
hold on;
% Plot the green signal
plot(greenChannel(1, :), 'g', 'LineWidth', 2);
% Plot the blue signal
plot(blueChannel(1, :), 'b', 'LineWidth', 2);
title('Colors as function of distance along x axis', 'FontSize', fontSize, 'Interpreter', 'None');
xlabel('Distance in Pixels', 'FontSize', fontSize');
ylabel('Gray Levels', 'FontSize', fontSize');
legend('Red', 'Green', 'Blue');
In addition, see the attached demo below, colormaps_plotted.m, where I do the same thing for any of the standard colormaps that you select.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by