I've got a frame in JPEG format.
I want to define if it's a fade in/out frame(which most of them are black frames) or not.
I read an article and tried to do exactly like that, but it wont work properly.
this is the idea:
At first the frame feature vector should be defined:
color histogram is computed only from the Hue component, which represents the dominant spectral component color in its pure form (Manjunath et al., 2001). Moreover, the quantization of the color histogram is set to 16 color bins, aiming at reducing significantly the amount of data without loosing important information
then it computes the standard deviation of the frame feature vector. The standard deviation of monochromatic frames is equal to zero or a sufficiently small value close to zero.4 This information is used by VSUMM to removes these frames. This step is also employed by Furini et al. (2010).
The code is in MATLAB:
str = num2str(50);
filename1=strcat('pics\' , str , '.jpeg');
Im1 = imread(filename1);
hsv = rgb2hsv(Im1);
hn1 = hsv(:,:,1);
hn1 = hn1/norm(hn1);
f=std2(hn1)
According to the idea f should be equal to zero or a sufficiently small value close to zero. it's correct for all fade in/out frame but the result is sometimes small value close to zero for usual frame which is wrong ,what is wrong with it?
As an example i upload 4 pictures:
the result for the fisrt two pics which are fade in/out frames are 9.3340e-04,9.9959e-04 and for the 3rd image which is a normal frame is 0.23 which all of these results are correct but then the result for some frames like the 4th one which is a normal frames is 8.2447e-04 which is wrong.
honestly this code is n't that important, i just want a code that distinguish normal frames from fade in/out frames.
Related
I have an image and I apply thresholding to it to apply binary mask.I draw histogram before and after the thresholding process.The histograms look like below.
The second figure which is after thresholding,doesn't show any peaks.Is that mean,my thresholding is wrong.Can anyone please explain these histograms.
Update
Image after thresholding
To summarize Sardar's comment, the horizontal range of your plot is tight. Simply loosen the range a bit so you can see the result better. Doing xlim([-0.5 1.5]); will certainly do that and we can see that in the last figure of your update. How you interpret the histogram... well, for black and white images, examining the histogram is never meaningful because there are only two possible intensities to examine - 0 and 1. Histograms usually give a glimpse as to the contrast of the image. If the histogram is spread out, this usually gives an indication that the image has high contrast. However, if the histogram is within a small range this usually means the image is poor contrast.
Remember that the histogram simply count the occurrence of instances in a data set. In this case, we are counting how many times we see 0 and 1 in the image. Referring to your last plot, this means that approximately 9000 pixels that are intensity 0 and approximately 4000 pixels that are intensity 1. This gives absolutely no indication as to the contrast or the spread of the intensities in your image. because there are only two possible intensities that are seen in the image. As such, to answer your question in such a long-winded way, the answer is that you can't really interpret anything.
The only thing I can possible suggest is that it tells you the ratio of object pixels to background pixels and could indicate a measure of quality. Usually when we determine what is an object and what are background pixels, we would expect that there would be more background pixels than object pixels to be able to discern this from the background. Therefore, the more black pixels you have the better it may be. That being said, I can't really say more unless you actually show us what your image looks like after you threshold it.
I recorded a sequence of depth images using Kinect v2. But the background brightness is not constant. But It keeps changing from dark to light and light to dark (i.e) .
So I was thinking to use Histogram normalization of each image in a sequence to normalise the background to the same level. Can anyone please tell me how I can do this?
Matlab has a function for histogram matching and their site has some great examples too
Just use any frame as the reference (I suggest using the first one, but there is no real reason to do so), and keep it for all the remaining frames. If you want to decrease processing time you can also try lowering the number of bins. For a uint8 image there are usually 256 bins, but as you'll see in the link reducing it still produces favorable results
I don't know if kinect images are rgb or grayscale, for this example Im assuming they are grayscale
kinect_images = Depth;
num_frames = size(kinect_images,3); %maybe 4, I don't know if kinect images
%are grayscale(3) or RGB(4)
num_of_bins = 32;
%imhistmatch is a recent addition to matlab, use this variable to
%indicate whether or not you have it
I_have_imhistmatch = true;
%output variable
equalized_images = cast(zeros(size(kinect_images)),class(kinect_images));
%stores first frame as reference
ref_image = kinect_images(:,:,1); %if rgb you may need (:,:,:,1)
ref_hist = imhist(ref_image);
%goes through every frame and matches the histof
for ii=1:1:num_frames
if (I_have_imhistmatch)
%use this with newer versions of matlab
equalized_images(:,:,ii) = imhistmatch(kinect_images(:,:,ii), ref_image, num_of_bins);
else
%use this line with older versions that dont have imhistmatch
equalized_images(:,:,ii) = histeq(kinect_images(:,:,ii), ref_hist);
end
end
implay(equalized_images)
I have several video sequences exhibiting light intensity flickering (under fluorescent light sources).
This is due to the shutter speed and/or sampling rate not being a whole multiple of the electrical frequency. For example - shooting video at 1/50 second shutter speeds with 60Hz electrical frequency.
In general - I need to solve this without knowing the sampling rate, electrical frequency, video frame rate. I just see the flickering and need to fix them.
The video scenes include moving objects as well (some move slow, some as fast as the rapid change in intensity due to the flickering).
Is there a well known method of dealing with such flickering?
Thanks!
The common method for removing flickering is along the following lines. Looking at the difference image between consecutive frames, the flickering should appear as a strong periodic signal along the vertical axis of the image. Therefore, it should have a strong coefficient in the frequency domain. Thus, the flickering can be detected and removed by finding the coefficients in frequency domain that represent the flickering in the difference image, nullifying them and transforming back to space domain.
In pseudocode this algorithm looks like this:
imDiff = I_{t+1} - I_t (Compute the difference between subsequent video frames)
imDiff = FilterImDiff(imDiff)
imDiffRowSum = RowSum(imDiff) (summing the rows of the diff image)
dctCoef = DiscreteCosineTransform(imDiffRowSum)
flickeringDctCoef = SomeHeuristicToFindFlickeringCoef(dctCoef)
flickeringIm = CloneColumn(InverseDiscreteCosineTransform(fixedDctCoef), numCols)
fixedimDiff = imDiff - flickeringIm
fixedI_{t+1} = I_{t+1} + fixedimDiff
where:
RowSum(x) takes an m x n image as input and returns a column vector of size m x 1 where element i contains the sum of the i'th row in the image x.
CloneColumn(x, n) takes a column vector x of size m and clones it n times in order to create an m x n matrix.
numCols is the number of columns in the input image.
a simple algorithm for SomeHeuristicToNullifyFlickeringCoef can be choosing the first couple of largest coefficients, if they are greater than a certain threshold.
FilterImDiff should discard stuff from the difference image that doesn't contain flickering, such as movement of foreground objects. For example, pixels that have a temporal difference that is greater than the maximal magnitude of flickering. Also, pixels that are too bright or too dark usually don't have flickering in them.
Here with i have attached two consecutive frames captured by a cmos camera with IR Filter.The object checker board was stationary at the time of capturing images.But the difference between two images are nearly 31000 pixels.This could be affect my result.can u tell me What kind of noise is this?How can i remove it.please suggest me any algorithms or any function possible to remove those noises.
Thank you.Sorry for my poor English.
Image1 : [1]: http://i45.tinypic.com/2wptqxl.jpg
Image2: [2]: http://i45.tinypic.com/v8knjn.jpg
That noise appears to result from camera sensor (Bayer to RGB conversion). There's the checkerboard pattern still left.
Also lossy jpg contributes a lot to the process. You should first have an access to raw images.
From those particular images I'd first try to use edge detection filters (Sobel Horizontal and Vertical) to make a mask that selects between some median/local histogram equalization for the flat areas and to apply some checker board reducing filter to the edges. The point is that probably no single filter is able to do good for both jpeg ringing artifacts and to the jagged edges. Then the real question is: what other kind of images should be processed?
From the comments: if corner points are to be made exact, then the solution more likely is to search for features (corner points with subpixel resolution) and make a mapping from one set of points to the other images set of corners, and search for the best affine transformation matrix that converts these sets to each other. With this matrix one can then perform resampling of the other image.
One can fortunately estimate motion vectors with subpixel resolution without brute force searching all possible subpixel locations: when calculating a matched filter, one gets local maximums for potential candidates of exact matches. But this is not all there is. One can try to calculate a more precise approximation of the peak location by studying the matched filter outputs in the nearby pixels. For exact match the output should be symmetric. Otherwise the 'energies' of the matched filter are biased towards the second best location. (A 2nd degree polynomial fit + finding maximum can work.)
Looking closely at these images, I must agree with #Aki Suihkonen.
In my view, the main noise comes from the jpeg compression, that causes sharp edges to "ring". I'd try a "de-speckle" type of filter on the images, and see if this makes a difference. Some info that can help you implement this can be found in this link.
In a more quick and dirty fashion, you apply one of the many standard tools, for example, given the images are a and b:
(i) just smooth the image with a Gaussian filter, this can reduce noise differences between the images by an order of magnitude. For example:
h=fspecial('gaussian',15,2);
a=conv2(a,h,'same');
b=conv2(b,h,'same');
(ii) Reduce Noise By Adaptive Filtering
a = wiener2(a,[5 5]);
b = wiener2(b,[5 5]);
(iii) Adjust ntensity Values Using Histogram Equalization
a = histeq(a);
b = histeq(b);
(iv) Adjust Intensity Values to a Specified Range
a = imadjust(a,[0 0.2],[0.5 1]);
b = imadjust(b,[0 0.2],[0.5 1]);
If your images are supposed to be black and white but you have captured them in gray scale there could be difference due to noise.
You can convert the images to black and white by defining a threshold, any pixel with a value less than that threshold should be assigned 0 and anything larger than that threshold should be assigned 1, or whatever your gray scale range is (maybe 255).
Assume your image is I, to make it black and white assuming your gray scale image level is from 0 to 255, assume you choose a threshold of 100:
ind = find(I < 100);
I(ind) = 0;
ind = find(I >= 100);
I(ind) = 255;
Now you have a black and white image, do the same thing for the other image and you should get very small difference if the camera and the subject have note moved.
alt text http://internationalpropertiesregistry.com/Server/showFile.php?file=%2FUpload%2F02468.gif358455ebc982cb93b98a258fc4d6ee60.gif
Is there a simple solution in MATLAB?
Easy answer: NOPE
For very simple: read the image as grayscale, threshold, clean up and run it through an ocr program.
%# read the image
img = imread('http://internationalpropertiesregistry.com/Server/showFile.php?file=%2FUpload%2F02468.gif358455ebc982cb93b98a258fc4d6ee60.gif');
%# threshold
bw = img < 150;
%# clean up
bw = bwareaopen(bw,3,4);
%# look at it - the number 8 is not so pretty, the rest looks reasonable
figure,imshow(bw)
Then, figure out whether there is an OCR program that can help, such as this one
For even simpler:
%# read the image
[img,map] = imread('http://internationalpropertiesregistry.com/Server/showFile.php?file=%2FUpload%2F02468.gif358455ebc982cb93b98a258fc4d6ee60.gif');
%# display
figure,imshow(img,map)
%# and type out the numbers. It's going to be SO much less work than writing complicated code
For a simple one like that you can probably just run a median filter and ocr.
A median filter will, for every pixel in the image, look at the area around it, usually a 3x3 or 5x5 pixel area, determine the median pixel value in that area and set the pixel to that median value. In a block of the same colour nothing will happen, the whole area is the same colour as the pixel under consideration so the median i sthe same as the current value (or at least almost the same permitting slight colour variations. On the other hand noise pixels, i.e. a single pixel with a differently coloured area around it will simply disappear, since the median value of the area will be the colour of all the pixels around the noise pixel.
As for the ocr, or optical character recognition, I'd just use an existing program/library, it would certainly be possible to write an ocr algorithm in Matlab, but would be a much bigger exercise than writing a simple algorithm in an hour. You'd first need to read up on ocr techniques and algorithms.
Clean up the image
Separate each character into distinct images
Compare each character against a set of reference characters
The best matches are the most likely original character
You may consult this post. I succeeded in cracking a simpler CAPTCHA with the illustrated approach.