How toimage regional analysis

조회 수: 2 (최근 30일)
bozheng
bozheng 2024년 3월 9일
편집: DGM 2024년 3월 9일
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
DGM
DGM 2024년 3월 9일
편집: DGM 2024년 3월 9일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

DGM
DGM 2024년 3월 9일
편집: DGM 2024년 3월 9일
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');

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by