How to enhance video frames in while cycle
Afficher commentaires plus anciens
Hi, I've a problem with the enhancement of video frames and I hope you can help me.
First, I have worked on a .png image taken from a .MOV video, converted it in gray scale, adjusted contrast and equalization, the following is the code:
image = 'name.png';
IMG = imread(image); % read image
I = rgb2gray(IMG); % convert image to gray scale
I2 = wiener2(I); % filter
I3 = imadjust(I2); % adjust contrast
contrast = 0.01;
I4 = adapthisteq(I3,'clipLimit',contrast,'Distribution','uniform'); % equalization
figure, hh = imshow(I4,'InitialMagnification', 'fit');
Now, I would like to do the same but directly with the video frames. Here is what I did:
xyloObj = VideoReader('name_video.MOV');
while hasFrame(xyloObj)
% Read frame
vidFrame = readFrame(xyloObj);
% Enhancement
I = rgb2gray(uint8(vidFrame));
I2 = wiener2(I);
I3 = imadjust(I2);
contrast = 0.01;
I4 = adapthisteq(I3,'clipLimit',contrasto);
figure (100), imshow( uint8(I4), 'InitialMagnification', 'fit');
pause(0.01)
end
The figure (100) shows an almost black image, despite the enhancement is the same of above (for the .png image worked quite well). I wonder why...
Thanks for the help!
Giovanni
ps. I attached 3 images to help you to understand my problem. Maybe you can suggest me also I to enhance that properly :)



Réponses (1)
Geoff Hayes
le 23 Juin 2016
Giovanni - in your while loop, you cast I4 as 8-bit unsigned integers which you don't do with your initial example. What can you tell us about the I4 from your while loop? Try executing the following commands
class(I4)
min(I4(:))
max(I4(:))
to determine the data type (class), minimum and maximum values in this matrix. It could be that they are doubles and in the interval [0,1] and so when you cast to the unsigned integers, you get zeros or ones. And if most of the values are zeros, then you would see a black image. I suspect that you may want to remove the cast...
Catégories
En savoir plus sur Video Formats and Interfaces 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!