I want to divide the 360 degree hue circle into 10 equal sector
Afficher commentaires plus anciens
Hiii...
I want to divide a hue image into 10 sectors.for that first i multiplied obtained hue image by 360.how can i do this?? is there any function to divide hue image into sectors.
Réponses (2)
Image Analyst
le 17 Nov 2012
Modifié(e) : Image Analyst
le 17 Nov 2012
How about logical indexing? Multiplying by 360 is not necessary. Why do you think it is?
h1 = h(h < 0.1);
h2 = h(h > 0.1 & h < 0.2);
h3 = h(h > 0.2 & h < 0.3);
etc. up to h10. If you want an image instead of a list of values, then you'll have to do masking
h2 = h .* double(h > 0.1 & h < 0.2);
etc.
11 commentaires
susithra dhanavel
le 9 Déc 2012
Image Analyst
le 9 Déc 2012
I have no idea whatsoever what that means.
susithra dhanavel
le 23 Jan 2013
Walter Roberson
le 23 Jan 2013
In another Question, we asked you to explain what you meant about non-adjacent sectors, but my recollection is that you did not respond with something we could understand.
On the other hand, in the above when IA referred to "masking", he meant "logical indexing in order to select which elements were to be affected."
susithra dhanavel
le 12 Fév 2013
Image Analyst
le 13 Fév 2013
Modifié(e) : Image Analyst
le 13 Fév 2013
You can't get the original hue image back because when you did the logical operations, you end up with 1D vectors and all spatial information is lost. Your h1 through h10 are 1D vectors. Do you need the h1 through h10 to be 2D images? Because that would require different formulas.
susithra dhanavel
le 13 Fév 2013
Thorsten
le 13 Fév 2013
See my code below. The B computed in each run of the loop are the h1, h2, ... images you need.
Image Analyst
le 13 Fév 2013
See my demo:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Read in a standard MATLAB color demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'peppers.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(3, 4, 1);
imshow(rgbImage, []);
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
hsv = rgb2hsv(rgbImage);
hueImage = hsv(:,:,1);
numberOfHues = 10;
for hue = 1 : numberOfHues
% Get a binary image of where this hue is.
mask = hueImage > (hue-1)/numberOfHues & hueImage <= hue/numberOfHues;
% Extract it from the image
% Mask the image.
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask,class(rgbImage)));
subplot(3, 4, hue+1);
imshow(maskedRgbImage);
caption = sprintf('Hue #%d Image', hue);
title(caption, 'FontSize', fontSize);
end
NUR LYANA SHAHFIQA ALBASHAH
le 2 Fév 2017
How about if want to use grayscale image?
Image Analyst
le 2 Fév 2017
That would be a totally different question. TOTALLY different. You can't even adapt the code above at all.
You'd have to create sectors with the FAQ http://matlab.wikia.com/wiki/FAQ#How_do_I_create_an_arc.3F and then use poly2mask() to get a masked image, if that's what you want.
Ncolors = 10;
I = imread('peppers.png');
HSV = rgb2hsv(I);
H = HSV(:,: ,1);
Hnew = zeros(size(H));
delta = 1/Ncolors;
for range = delta:delta:1
B = H >= range - delta & H < range;
Hnew(B>0) = range - delta/2;
end
HSV(:,:,1) = Hnew;
subplot(1,2,1), imshow(I)
subplot(1,2,2), imshow(hsv2rgb(HSVnew))
2 commentaires
susithra dhanavel
le 4 Avr 2013
Walter Roberson
le 4 Avr 2013
Image Analyst's demo of February 13th shows you one way to proceed.
Catégories
En savoir plus sur Display Image dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!