How to enhance video frames in while cycle
Show older comments
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 :)



Answers (1)
Geoff Hayes
on 23 Jun 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...
1 Comment
Giovanni Pavese
on 23 Jun 2016
Categories
Find more on Video Formats and Interfaces in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!