So I have an image. I take it into HSV format and v has its intensity values.

now the intensity values of v vary from 0 to 1 (Black to White)

I want to divide v into 3 parts:

1] v1= with intensity values 0<v<0.3

2] v2= with intensity values 0.3<v<0.75

3] v3= with intensity values 0.75<v<0.1

How do I do this?


1 Answer 1


All you need to do is masking on your v we remember and image is a [rows,cols,layers] matrix, where the layers are Hue=1,saturation=2,intensity value=3

We then create a mask (array of 0s and 1s). For example your first range would be

v1 = (hsv_im(:,:,v_idx) <0.3);

we are taking the all rows, all columns, of layer v, and if the value is <0.3 make it 1, otherwise make it 0. Now to see only those pixels we can multiply the original value array by our mask.

hsv_im(:,:,v_idx) = v0.*v1_mask;

As you recall any value >0.3 was 0 in our mask, so all the other areas will be blacked out.

here is a full example

im = imread('flower.jpg');
hsv_im = rgb2hsv(im);
v_idx =3; 

v0 = (hsv_im(:,:,v_idx));    %the original
v1_mask = (hsv_im(:,:,v_idx) <0.3);
v2_mask = (hsv_im(:,:,v_idx) <=0.3 & hsv_im(:,:,v_idx) <0.75);
v3_mask = (hsv_im(:,:,v_idx) >= .75);

%plots the images

hsv_im(:,:,v_idx) = v0.*v1_mask;
subplot(2,2,2);imshow(hsv2rgb(hsv_im));title('0.00< v<0.30')

hsv_im(:,:,v_idx) = v0.*v2_mask;

hsv_im(:,:,v_idx) = v0.*v3_mask;

%plots the masks
subplot(2,2,1);imshow(v0);title('original v')
subplot(2,2,2);imshow(v1);title('0.00< v<0.30 mask')
subplot(2,2,3);imshow(v2);title('0.30<=v<0.75 mask')
subplot(2,2,4);imshow(v3);title('0.75<=v<= 1  mask')

the original image showing only the regions that match the search criteria the masks for each of the 3 v ranges


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.