Assembly |
![]() |
Computer Organization and Assembly Languages, Fall 2007
|
Jump to...
assignment #1
|
Assignment #3: Box FilterAssigned: 11/21/2007Due: 12/09/2007 11:59pm DescriptionSmoothing filters are useful image processing tools for blurring and for noise reduction. They use spatial coherence and pixel value homogeneity of a pixel's neighborhood as bases. Noise-cleaning techniques detect lack of coherence and either replace the incoherent pixel value by something more spatially coherent by using some or all of the pixels in a neighborhood containing the given pixel or smooth the pixel value with others in an appropriate neighborhood. The operator that computes the equally weighted average is called the box filter operator.Given an image f, the box filter operator with a (2M+1)X(2N+1) smoothing neighborhood is defined by ![]() where k(r, c) represents the pixel value of the filtered image k at the r-th row and the c-th column. In this assignment, you have to implement an ARM assembly procedure for a 3x3 box filter and test it on a GBA emulator. Note that, for a 3x3 filter, a corner pixel only averages on 4 pixels, a border pixel on 6 pixels and a interior pixel on 9 pixels. For developing ARM assembly programs, we recommend HAM GBA DevKit. If you are familiar with Makefile, you can use DevKitARM or DevKit Advance instead. Although directly implementing the above function produces the correct filtering result, naïve implementation can be slow. Since such image-processing techniques usually have to meet the timing constraint for interactive playing, please try to improve its speed. PreparationWe assume that you will use HAM as the development kits. Follow the following steps to install HAM.
SpecificationYou have to implement myfilter.s as the 3x3 box filter. This function's prototype isvoid myfilter(u16* ret, const u16* ori);where ret is a pointer pointing to the output destination and ori is a pointer pointing to the input image data. ret is stored in R0 and ori is stored in R1. A skeleton code looks like: .file "myfilter.c" .text .align 2 .global myfilter .type myfilter, %function myfilter: ldrh r2, [r1, #0] @ movhi @ * ori strh r2, [r0, #0] @ movhi @ * ret bx lr .size myfilter, .-myfilter .ident "GCC: (GNU) 3.3.2"Your job is to replace the two lines after the label myfilter (they are just placeholder) with the complete code for box filtering. In the template file, you can find the files you might need and main.cpp where other functions are implemented. They are used for image I/O and do timings, and you don't need to modify them. A function called boxfilter() in boxfilter.c is a C implementation of the 3x3 box filter. The results of your ASM filter should be exactly the same as the output of this C implementation. void boxfilter(u16 *ret,const u16* ori) { u32 r,g,b; u32 cc; int x,y,dx,dy; for(y=0;y<160;y++) { for(x=0;x<240;x++) { cc = r = g = b = 0; for(dy = -1;dy<=1;dy++) { for(dx=-1;dx<=1;dx++) { int nx = x+dx; int ny = y+dy; u16 ncolor; if(nx < 0 || ny < 0 || nx >=240 || ny >= 160) continue; ncolor = ori[ny*240+nx]; cc++; r+= (ncolor&0x001f); g+= ((ncolor&0x03e0)>>5); b+= ((ncolor&0x7c00)>>10); } } r = r/cc; g = g/cc; b = b/cc; ret[y*240+x] = (b<<10)+ (g<<5) + r; } } }Note that GBA uses the BGR5 format in which every pixel uses 2 bytes. The lowest five bits are for red, the middle five for green and the higher five for blue. The highest bit is not used. If you would like to test on your own image, you can use the utility gfx2gba to convert your image. You can obtain gfx2gba from here. This program converts an input image into a C header file for the input image in GBA's image format. Replace input.h with the generated header file. GradingYou will get 85 points if you implement this procedure correctly. Another 0~20 points will be added to your grade depends on the speed of your program and 0~5 points depends on the code size.SubmissionWe have provided a set of test images at here. Uncompress the archives under the directory where your hw3 project is at. Execute startham.bat under $HAM, where you have installed HAM. The, under hw3 directory, execute "test_input N", where N=1..5, to test on different images. Submit your homework through online submission system. |
|||||||
![]() |
![]() |