필터 지우기
필터 지우기

how to access rgb spectrum through array

조회 수: 1 (최근 30일)
James Robinson
James Robinson 2022년 12월 8일
답변: Image Analyst 2022년 12월 8일
im working on color masking an image and i have color threshholds that i am trying to compare each pixel to but i keep recieving "Index in position 2 exceeds array bounds. Index must not exceed 1500."

답변 (1개)

Image Analyst
Image Analyst 2022년 12월 8일
You should really use the Color Thresholder app on the Apps tab of the tool ribbon. Set your thresholds there and then use the button to export the code.
Your thresholds are not in the range for HSV images (0-100 for V, 0-1 for H and S). They're more in the range like youi'd use for RGB thresholding. They look like they will threshold for cyan color, not yellow. Here is the code:
rgbImage = imread("practice2.jpeg");
[rows, columns, numberOfColorChannels]=size(rgbImage);
% hsvImage=rgb2hsv(rgbImage);
% Define mask to find cyan (not yellow).
yellow_low = ([20,100,100]);
yellow_high = ([30,255,255]);
[r, g, b] = imsplit(rgbImage);
mask = (yellow_low(1) < r & r < yellow_high(1)) &...
(yellow_low(2) < g & g < yellow_high(2)) & ...
(yellow_low(3) < b & b < yellow_high(3));
subplot(2, 1, 1);
imshow(rgbImage);
impixelinfo;
subplot(2, 1, 2);
imshow(mask)
Since there is no cyan in your image, the mask shows nothing.
Why did your code throw an error? Because you used size wrong and forgot to include the third output argument.
See Steve's blog for an explanation:

카테고리

Help CenterFile Exchange에서 Image Segmentation and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by