我要编写一个用于直方图均衡化的脚本,我需要分别在每个 RGB 平面上工作。在第一步中,我计算每个强度值在 0-255 范围内的出现次数。据我所知,使用for
循环会使 MATLAB 代码超慢。这就是我想出的:
org_image = imread('image.jpg')
tot_pixel = size(org_image,1) * size(org_image,2)
R = org_image(:,:,1);
G = org_image(:,:,2);
B = org_image(:,:,3);
[R_val_ocurr,R_unique_val] = histcounts(R);
[G_val_ocurr,G_unique_val] = histcounts(G);
[B_val_ocurr,B_unique_val] = histcounts(B);
现在有一个大小为 256 的数组,每个索引保存与其对应的像素数,下一步应该是什么?我正在尝试写下我的逻辑:
for i = 0 to 255
if i is in R_unique_val
hist[i] = R_val_ocurr[i]
else
hist[i] = 0
如何在 MATLAB 中正确有效地编写它?
分离通道后,您可以使用imhist获取每个通道的直方图:
[NumberOfPixelR, intensity] = imhist(R);
[NumberOfPixelG, intensity] = imhist(G);
[NumberOfPixelB, intensity] = imhist(B);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句