One of the biggest problems with computer science in academia is the fact that most instructors don’t get much time to code anything. The code I write is often quite simplistic… a library here, a function there. Few academics write apps, or large programs (> 10,000 LOC) – there just isn’t the time. I am in the midst of writing a small image processing library for Julia. but it won’t compete with JuliaImages from a code perspective. I have looked at some of the code there, and honestly I can’t make heads nor tails of it – it seems well written of course, but it is extremely complex from my perspective. That, and I don’t like OO, never have. So the library I am cobbling together (it is a craft isn’t it?), will be written in basic Julia. No OO, no functional, just what is essentially pure procedural. But it will be possible to figure out what is happening in the code, which I think is important. There is nothing worse than a piece of code written by someone else, that performs its task admirably, but looking at it sends you into fits of convulsion because it is indecipherable. And this seems to happen a lot… it’s almost as bad as trying to figure out some algorithm in a paper, where the author quite clearly has no ability to actually explain how the algorithm works.
Consider this simple function to calculate a threshold (turning a grayscale image into a binary one) using the classic Otsu method:
# Function to perform image thresholding using Otsu's algorithm # # Type: clustering threshold algorithm # # Parameters: # (in) img : gray-scale image # (in) nBin : number of bins in the histogram (default=256) # (out) tvalue : threshold value # # Example: t = otsu(img) # # Ref(s): # Otsu, N., "Threshold selection using grey level histograms", IEEE # Transactions on Systems, Man and Cybernetics, Vol.9(1), pp.62-66 (1979) # # Notes: Variables coincide with the original paper function otsu(img, nBin=256) dx,dy = size(img) imgSize = dx * dy imgN = copy(img) # Get the image histogram hst = getIMGhist(img) # Normalize the histogram 0->1 (Eq.1) hstP = hst / imgSize # Total mean level of the original image (Eq.8) mu_T = 0.0 for i = 1:nBin mu_T = mu_T + i * hstP[i] end sigma = zeros(Float32, nBin) for k = 1:nBin # Zero-order cumulative moments up to the t-th level w_k = sum(hstP[1:k]) # (Eq.6) # First-order cumulative moments up to the t-th level mu_k = 0.0 for i = 1:k mu_k = mu_k + i * hstP[i] # (Eq.7) end # Variance of the class separability (Eq.18) if (w_k != 0.0) && (w_k != 1.0) sigma[k] = ((mu_T * w_k - mu_k)^2.0) / (w_k * (1.0-w_k)) else sigma[k] = 0.0 end end # Choose the threshold for which the variance of class # separability is at its maximum. Return the index of # this value (Eq.19) tvalue = indmax(sigma) return tvalue end
It is by no means perfect, but it works, and to the novice programmer it should be easy to read. There is enough documentation to look at the code, and see where each part of the algorithm exists in the original publication that described the algorithm. This makes it easy to modify, or even to check for potential faults in the code.
It would be really cool to have the time to build an app, but the reality is, I don’t have the development skills to do so. Few instructors do. If I were writing apps as a profession it would be a different thing altogether, but I don’t. In fact it’s hard to write anything meaningful in snippets of code. So remember that when you are taking a class on software development, chances are the instructor has never designed (or implemented) a large scale piece of software (and by large scale, I mean 25,000-100,000 LOC, which is trivial in terms of todays software industry).