CS50 is a first year university course offered by Harvard University and more recently, Yale University, which dives into the basics of computer science, exploring algorithmic thinking and teaching students how to code in a variety of languages including Scratch, C, and Python, amongst others. In the last few weeks of the course, it offers a choice of three tracks - game, web, or mobile development that students can explore and create their final project which is encouraged to be something which is useful beyond the course.
The online course which is known as CS50x offers a stripped down experience of the real course. The assignments, known as problem sets (or psets), are marked against certain criteria and a number of test cases by an automated program. All of your coursework is pushed into individual branches of your own CS50 GitHub repository. I’ve copied these branches into a single repository for ease of perusal, which can be found here.
I was kind of excited for week 4 when I read what the problems would cover. This week looked into processing bitmaps and recovering multiple JPEG files from a single disk image (simplified, naturally).
The bitmap processing problem involved implementing a variety of filters - greyscale, sepia, reflect, blur, and edge detection (more comfortable). I started off by reading all the code that was provided to me, line by line and understanding what each did, which I’m glad I did because it gave me a solid understanding of the kinds of data structures I was working with in order to solve the problems given.
The greyscale filter was achieved by averaging the RGB values of each pixel. Sepia had a formula that multiplied and added the various values together. Reflect reads each line backwards in order to horizontally reflect the image. Blur applied an average of all pixels surrounding the current pixel - this was kind of hard because it needed to detect the edges of the image and compensate appropriately. Finally, the more comfortable problem was to implement the Sobel edge detection algorithm - this involved applying a matrix to each of the surrounding pixels and adding them together.
The edge detection algorithm was a lot easier after I figured out the blur function. It created a pretty cool effect, an example of which I’ve included below that anyone should be able to recognise.
Edge Detection in Action
The recovery problem takes a raw data file and splits out individual JPEG files. Naturally this problem was somewhat simplified from how a real recovery program would work, as the blocks were all stored together however it was a pretty cool application of some of the concepts I’d learned.
All these problems gave me a really nice introduction to pointers and file operations. I’ve tried to understand pointers multiple times over the year however never really grasped them or the point (pun unintended) of using them. This has been one of the great things about CS50 - learning the underlying concepts that many other resources tend to just skim over and assume that you already know.