Skip to content

christinapramode/ImageInterpolation

Repository files navigation

Image Interpolation in C

This project involves developing an algorithm to carry out image interpolation in C, running and optimizing the code in a DSP Processor simulator using Texas Instruments' Code Composer Studio v5.5.


Step 1 - Developing the C code

Problem Statement:

Given a grayscale image of size WxH, interpolate into an image of size 2WxH. i.e., for an input image of size 256x256, the output image size would be 512x256. The code should fill in the extra output pixels by interpolating using the formula - (a+b+1)/2

The code involves the following steps:

  1. Creating/opening the input ("Image1_256x256.raw") and output files ("Image1_512x256.raw").
  2. Reading from the input file (row by row), and storing the pixel data in a pointer array "rev".
  3. Calling the function "interpImg", which carries out the interpolation and stores the result in another pointer array "revout".
  4. Writing to the output file (row by row).
  5. Closing all files.

Refer to "ImageInterp.c" for the full code

References:

For more information regarding the basics of images & image processing -

For more information regarding image interpolation -

Codes for reading raw images -


Step 2 - Running and Optimizing the Code on Ti CCS

Step 2.1 - Running the Code

Before running the code in CCS, profiling is added to measure the time taken for running the "interpImg" function. The header file "<c6x.h>" is included and the 64 bit TSC register (timer) is initialized before calling "interpImg", and ended afterwards. "sumcycles" stores the total cycles taken.

Refer to "ImageInterpCCS.c" for the full code

Step 2.2 - Further Optimization of the Code

For further optimization, we use intrinsics functions to perform SIMD (Single Instruction Multiple Data) operations in the function definition to compute the values of the extra output pixels.

The intrinsics functions used for Image Interpolation include -

_mem4, _amem4, _unpklu4, _unpkhu4, _swap4, _shrmb, _avgu4, _add4

Details on C66x intrinsics are available at Texas Instruments' TMS320C6000 Programmer's Guide -

Refer to "ImageInterpOptimized.c" for the full code

Optimization Cycles:

Note:

The values for optimization levels 0, 1, 2, 3 were obtained by changing the levels in the CCS IDE properties window. (Code used - "ImageInterpCCS.c")

The value for optimization level 4 was obtained by selecting level 3 in the CCS IDE properties window and using the code - "ImageInterpOptimized.c", i.e. the code using the intrinsics function.

DSP Simulator details - Device Family: "C6000" , Variant: "Generic C66xx Device", Target Configuration: "C6678 Device Cycle Approximate Simulator", "Little Endian"


For clarifications, contact me at christinapramode@gmail.com

About

Image Interpolation in C, Running & Optimizing code in a DSP processor using Texas Instruments' Code Composer Studio (CCS)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages