フィルターのクリア

Hue value of a specific pixel

2 ビュー (過去 30 日間)
Tasneem Al-Tmimi
Tasneem Al-Tmimi 2017 年 11 月 1 日
コメント済み: Image Analyst 2017 年 11 月 6 日
I have a segmented image I, I have used labeling to find the segmented objects, and using region props function I have extracted the centroid pixel value.
My question is:
Is there a way to find the hue value of this specific pixel value in my case the centroid ?

採用された回答

Image Analyst
Image Analyst 2017 年 11 月 1 日
Yes
hsvValues = rgb2hsv(rgbValues);
hueValue = hsvValues(:,:,1);
  5 件のコメント
Image Analyst
Image Analyst 2017 年 11 月 2 日
Centroid will be a floating point number with fractional values, so you need to round it to the nearest integers.
Tasneem Al-Tmimi
Tasneem Al-Tmimi 2017 年 11 月 3 日
Yes I know in the xyCentroid matrix I did this
xyCentroid = zeros(numberOfBlobs, 2);
for i=1:numberOfBlobs
x = 2*i-1;
y = 2*i;
xyCentroid(i,1) = floor(blobCentroid(x,1));
xyCentroid(i,2) = floor(blobCentroid(y,1));
end
But the problem is when having an image with two blobs (objects) I got this error
Error Message:
Index exceeds matrix dimensions.
That is related to the centroid pixels matrix
In the original image the hue value of the centroid pixel = 0 is this related ??
I have attached the image :)

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2017 年 11 月 4 日
Why not just get the mean hue of the whole thing?
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 25;
%===============================================================================
% Get the name of the image the user wants to use.
baseFileName = 'IMG_7379_2.jpg';
% Get the full filename, with path prepended.
folder = pwd
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
%===============================================================================
% Read in demo image.
rgbImage = imread(fullFileName);
% Get the dimensions of the image.
[rows, columns, numberOfColorChannels] = size(rgbImage);
% Display the original image.
subplot(1, 2, 1);
imshow(rgbImage, []);
axis on;
caption = sprintf('Original Color Image, %s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo();
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0.05 1 0.95]);
% 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')
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Create the region of interest (ROI)
Igray = rgb2gray(rgbImage);
binaryImage = ~imbinarize(Igray);
% Take largest 2 blobs only
binaryImage = bwareafilt(binaryImage, 2);
% Fill them to get rid of noise.
binaryImage = imfill(binaryImage, 'holes');
% Display the mask image.
subplot(1, 2, 2);
imshow(binaryImage, []);
axis on;
caption = sprintf('Binary Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo();
drawnow;
% Convert rgb to hsv
hsvImage = rgb2hsv(rgbImage);
hueImage = hsvImage(:, :, 1);
% Compute the mean hue within the mask:
meanHue = mean(hueImage(binaryImage))
message = sprintf('The mean hue angle is %f', meanHue);
uiwait(helpdlg(message));
% Measure properties of the blobs.
% props = regionprops(binaryImage, 'Centroid');
  5 件のコメント
Tasneem Al-Tmimi
Tasneem Al-Tmimi 2017 年 11 月 6 日
編集済み: Tasneem Al-Tmimi 2017 年 11 月 6 日
The f is related to rounding number :)
Yes you got the point that am stuck on it, that sometimes when I get the mean the value detect it as a green color not red and the main objective of my code is to detect the color of my object that is Date Fruit, sometimes it is green, yellow, red, brown my problem is always related to the red color !
My question is that trick by subtracting -0.5 from the values I have ??
And in LAB color space you mean taking the mean of L ??
Image Analyst
Image Analyst 2017 年 11 月 6 日
No, the square root of a squared and b squared, like I said. LAB color space should work for any color.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by