Change brightness in images
Afficher commentaires plus anciens
Hey there,
i have a video where some frames are brighter than others and i want to set it all to the same level. I created a mask on a specific area of the images and converted the images to hsv, since the video is in rgb. Then i calculate the mean of the v-Channel in that specific area to get something like a brightness of every frame, and write that value in a matrix. After every image is processed I'm calculating the mean of all the images to get a brightness of the video in total. In a second loop I'm calculation the difference between the brightness of each image and the mean brightness of the complete video and add that difference to a new v-Channel and convert it back to rgb. The code is working fine but there doesn't seem to be any effect on the brightness of the frames. Does anyone have another idea?
imDouble = im2double(vidRGB);
imHSV = rgb2hsV(imDouble);
vChannel = imHSV(:,:,3);
vChannelMasked = vChannel .* maskLight;
lightnessMeanHSV(k,:) = sum(lChannelMasked, 'all')/nnz(vChannelMasked);
% Second Loop :
lightnessMeanHsvAll = mean2(lightnessMeanHSV);
imRGB = read(vid, iii);
imDouble = im2double(imRGB);
imHSV = rgb2hsv(imDouble);
hChannel = imHSV(:,:,1);
sChannel = imHSV(:,:,2);
vChannel = imHSV(:,:,3);
lightnessDiff = lightnessMeanHsvAll - lightnessMeanHSV(ii,:);
vChannelNew = vChannel + lightnessDiff;
imHsvNew = cat(3, hChannel, sChannel, vChannelNew);
imRgbNew = hsl2rgb(imHsvNew);
1 commentaire
When you say there doesn't seem to be any effect, do you mean that it's insufficient for your requirements or is it actually a measured zero change? It's hard to tell what's going on when half the code is missing. For all I can tell, imRgbNew is never saved to anything. What's lChannelMasked? What are the dimensions of lightnessMeanHSV?
I also don't know why you're using hsl2rgb to back convert an hsv image.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Image Preview and Device Configuration dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


