Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想从 MATLAB 中的文件夹中读取 RGB 图像(.jpg),扫描图像的每个像素并检查它是否具有特定颜色(例如,如果它是 Violet: R 128,G 0, B 255)并计算有多少像素具有这种特定颜色。
R 128,G 0, B 255
你有想法吗?
假设图像被加载到名为的变量中A:
A
pixelMask = A(:,:,1) == 128 & A(:,:,2) == 0 & A(:,:,3) == 255; count = nnz(pixelMask);
另一种方法是使用bxsfun和单例扩展:
bxsfun
pixel = cat(3,128,0,255); S = all(bsxfun(@eq, A, pixel), 3); count = nnz(S);