I am to write a script for histogram equalisation and I need to work on each RGB plane separately. In the first step I count the number of occurrences of each intensity value in the range 0-255. As far as I know, using for loops makes MATLAB code super slow.
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);
Now to have an array of size 256,with each index holding number of pixels corresponding to it what should my next step be? I'm trying to write down my logic :
for i = 0 to 255 if i is in R_unique_val hist[i] = R_val_ocurr[i] else hist[i] = 0
Please tell me how to correctly and efficiently write this.
Best Answer