Time for action – deinterlacing with the scan line interpolation

In this example, we will demonstrate an alternative method for deinterlacing, based on the averaging of the lines above and below the interlaced one. Since only a minor change will be made in step 3 of the previous process, we will show this process in a little less detail:

  1. First, we will repeat steps 1 and 2 from the previous example, to load our image and preallocate space:
    >> A = imread('interlaced.bmp'),  % Load interlaced image
    >> B = uint8(zeros(size(A)));  % Pre-allocate space for the result
  2. Before we proceed, we must first convert the input to type single so that the averaging process is not confined to the range of values 0-255:
    >> A = single(A);  % Convert input to single
  3. Now, we will write the exact same loop as before, with only one minor change; we will replace the line repetition with an averaging process:
    >> for i = 1:size(A,1)-1,   % For all rows in A (except the last)
    if mod(i,2) == 0,       % if i is even
    % Replace i-th row of C with average of (i-1)-th and (i+1)-th of A
    C(i,:,:) = round((A(i-1,:,:) + A(i+1,:,:)) / 2);  
    else     % if i is odd
    C(i,:,:) = A(i,:,:);    % Replace i-th row of B with i-th row of A
    end     % End if
    end    % end for	
  4. Before demonstrating the results, we have to do two things. Make the last row of the image equal to the one above it and revert the input to its original state (type uint8):
    >> C(end,:,:) = A(end-1,:,:);
    >> A = uint8(A); % Convert A back to uint8
  5. Once again, we demonstrate our results:
    >> A2 = imcrop(A,[480 400 200 100]); % Crop interlaced image
    >> C2 = imcrop(C,[480 400 200 100]); % Crop deinterlaced frame
    >> subplot(1,2,1),imshow(A2);title('Cropped Interlaced Area')
    >> subplot(1,2,2),imshow(C2);title('CroppedDe-Interlaced Area') 
    Time for action – deinterlacing with the scan line interpolation

What just happened?

This time we tried something a little more complicated than a simple line replacement. The pixels in even rows of the input were substituted by the average values of the pixels in the rows above and below (in the respective column). This way, the jagged artifacts were further reduced and there were also less blurring and flickering. The differences from the previous example were not too many.

After loading our input image and preallocating space for the output, we converted the input to type single, because we wanted to be able to add values that could exceed the maximum uint8 value without being clipped to 255 (for example, the single type result of 140 + 180 will be 320, while the uint8 type result would be 255).

The for loop had only two small differences to the one in the previous example. The first one was that we do not include the last row in the loop, because the value of i + 1 would fall off limits. The second difference was that we did not replace even rows with the ones above them, but we replaced them with the average of the ones above and below them.

To complete our process, we converted the input back to type uint8 and also replaced the last row of the output image (which was not filled in the loop) with the row above it. Finally, we demonstrated the results in the cropped area we used in previous examples so that we saw the differences. The result should be identical to the one generated using the linear interpolation method in previous examples.

Have a go hero – comparing the deinterlacing methods

Now that you have seen how two of the three methods included in the Deinterlacer object can be implemented, you should try to make your own custom function that applies them to an input image. The function (let's call it MyDeinterlacer.m) should take two inputs: the interlaced image and the choice of method. The output should be the deinterlaced image generated by the process.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset