How toimage regional analysis
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sorry to bother you all , i have a picture but i dont konw the picture(size 869 *755) is RGB or CMYK ,the scond quesion is i will want to conduct regional analysis (can viwer can tell me how to cut two parts ----yellow and red) and bellow is i coding about get red region
img = imread('test sample.jpg');
img = rgb2hsv(img);
hue_range = [0.9, 0.1];
mask = inrange(img(:,:,1), hue_range(1), hue_range(2));
cropped_img = imcrop(img, mask);
cropped_img = hsv2rgb(cropped_img);
imshow(cropped_img);
but will say error on "mask=inrange......"
I hope someone can help me, I will sincerely thank you
1 comentario
DGM
el 9 de Mzo. de 2024
Editada: DGM
el 9 de Mzo. de 2024
You didn't attach any image, so I can't tell you anything about the colorspace used by the file.
inrange() is not a function in base MATLAB or any official toolbox, so nobody knows what it is. If you don't know what it is, then I'd have to ask where you got the code. Otherwise I don't know why you'd write that line.
Similarly, that's not how imcrop() works.
Respuestas (1)
DGM
el 9 de Mzo. de 2024
Editada: DGM
el 9 de Mzo. de 2024
If all you're trying to do is select red regions with a mask:
rgbimg = imread('peppers.png');
hsvimg = rgb2hsv(rgbimg);
hue_range = [0.9, 0.1];
mask = hsvimg(:,:,1)>=hue_range(1) | hsvimg(:,:,1)<=hue_range(2);
% this doesn't make any sense
%cropped_img = imcrop(rgbimg, mask);
imshow(mask,'border','tight');
As to what you're trying to do with imcrop(), I don't know. That's not how imcrop() is used, so it's hard for me to guess. I have two guesses.
If you want to get only the scattered pixels associated with the mask, it won't be a rectangular image anymore, so it doesn't make sense to display it.
selectedpixels = rgbimg(repmat(mask,[1 1 3]));
selectedpixels = reshape(selectedpixels,[],3); % a 3-column RGB color table
Alternatively, you could crop the image to the bounding box of the mask, but for all I know, the bounding box is the same size as the image, so I don't know if that makes sense either.
% crop both the image and mask to the bounding box of the mask
[croppedmask rows cols] = crop2box(mask);
croppedrgb = rgbimg(rows,cols,:);
imshow(croppedrgb,'border','tight');
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!