how to access rgb spectrum through array

2 ビュー (過去 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 Center および File ExchangeImage Segmentation and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by