MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

New to MATLAB?

# I want to divide the 360 degree hue circle into 10 equal sector

### susithra dhanavel (view profile)

on 16 Nov 2012

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.

## Products

No products are associated with this question.

### Image Analyst (view profile)

on 17 Nov 2012
Edited by Image Analyst

### Image Analyst (view profile)

on 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.

susithra dhanavel

### susithra dhanavel (view profile)

on 13 Feb 2013

yes i want h1 through h10 to be 2D image..then what is the code in matlab??

Thorsten

### Thorsten (view profile)

on 13 Feb 2013

See my code below. The B computed in each run of the loop are the h1, h2, ... images you need.

Image Analyst

### Image Analyst (view profile)

on 13 Feb 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
% 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
subplot(3, 4, hue+1);
caption = sprintf('Hue #%d Image', hue);
title(caption, 'FontSize', fontSize);
end
```

### Thorsten (view profile)

on 12 Feb 2013
Edited by Thorsten

### Thorsten (view profile)

on 12 Feb 2013
```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))
```

susithra dhanavel

### susithra dhanavel (view profile)

on 4 Apr 2013

Thank you...I want to create a 306 degree hue circle in matlab and then I want to divide that hue circle into ten sectors..i tried to create but I dint get it...what is the code to create hue circle???

Walter Roberson

### Walter Roberson (view profile)

on 4 Apr 2013

Image Analyst's demo of February 13th shows you one way to proceed.