I've never seen this feature of Edita before when playing with the Euphoria language. Now I'm playing with an updated installation of Phix, which still has Edita in the demo folder. There is a feature in it now for publishing the code into HTML which I think is really handy for this blog.
I just copy and past that HTML code into Blogger here and see the results. Then add some description paragraphs to talk about the code.It's pretty handy!
So here was my last real application of Euphoria for work, used to analyze some infrared images that I converted to plain text for easy parsing. This script won't be used anymore since that system has been decomissioned.
-- processImageData.ex -- Jovan Trujillo -- Flexible Electronics and Displays Center -- Arizona State University -- 3/29/2017 -- -- Create a Euphoria program that will investigate some image processing tasks -- Test with file image_data/IR_X-29055.17_Y-35317.56_E1709-001_Repair_Panel_2_MF1_C-R.txt -- I could have Euphoria call ImageJ in console mode somehow to convert the image it's looking at into a temporary text file. -- Then analyze the data. include std/console.e include std/math.e include std/sequence.e include csv.e function objSubtract(object x, object y) return x - y end function procedure main() sequence myFile = "image_data/IR_X-29055.17_Y-35317.56_E1709-001_Repair_Panel_2_MF1_C-R.txt" object fn = open(myFile, "r") object line sequence image = {} integer i i = 1 while 1 do line = gets(fn) if atom(line) then exit end if image = image & parse_line(line,{"," , " " , "\t"}) i += 1 end while -- Done reading file, now print information about matrix that has been created printf(1, "Dimensions of image is: %d x %d\n", {length(image), length(image[1])}) -- Find max value and min value atom myMax = max(image) atom myMin = min(image) printf(1, "Maximum pixel value is: %d\n", {myMax}) printf(1, "Minimum pixel value is: %d\n", {myMin}) ?image[1][1] ?image[1][2] ?image[2][1] ?image[2][2] -- The values given in the image matrix are not what I expected. They are not 32000 level numbers. Max is 57, min is 9 -- Scan the image data row by row and report the standard deviation atom total = 0.0 atom stdDev = 0.0 atom mean = 0.0 sequence sTotal = {} sequence sStdDev = {} sequence sMean = {} for j = 1 to length(image) do total = sum(image[j]) mean = total / length(image[j]) stdDev = sqrt( sum( power( apply(image[j], routine_id("objSubtract"), mean), 2)) / (length(image) - 1) ) sTotal = append(sTotal, total) sStdDev = append(sStdDev, stdDev) sMean = append(sMean, mean) end for printf(1, "Row with highest total: %d\n", {max(sTotal)}) printf(1, "Row with lowest total: %d\n", {min(sTotal)}) printf(1, "Row with highest average: %d\n", {max(sMean)}) printf(1, "Row with lowest average: %d\n", {min(sMean)}) printf(1, "Row with highest deviation: %d\n", {max(sStdDev)}) printf(1, "Row with lowest deviation: %d\n", {min(sStdDev)}) -- Now do the same analysis with the columns sTotal = {} sStdDev = {} sMean = {} sequence tImage = repeat(0, length(image)) -- Column index is j for j = 1 to length(image[1]) do -- Row index is k and I need to copy along row k column j to do the math for single column for k = 1 to length(image) do tImage[k] = image[k][j] end for total = sum(tImage) mean = total / length(tImage) stdDev = arrayStdDev(tImage) sTotal = append(sTotal, total) sMean = append(sMean, mean) sStdDev = append(sStdDev, stdDev) end for printf(1, "Column with highest total: %d\n", {max(sTotal)}) printf(1, "Column with lowest total: %d\n", {min(sTotal)}) printf(1, "Column with highest average: %d\n", {max(sMean)}) printf(1, "Column with lowest average: %d\n", {min(sMean)}) printf(1, "Column with highest deviation: %d\n", {max(sStdDev)}) printf(1, "Column with lowest deviation: %d\n", {min(sStdDev)}) close(fn) any_key() end procedure function arrayStdDev(sequence mySeq) atom mean atom stdDev mean = sum(mySeq) / length(mySeq) stdDev = sqrt( sum( power( apply(mySeq, routine_id("objSubtract"), mean) , 2) ) / (length(mySeq) - 1) ) return stdDev end function main()
Maybe I'll just dedicate this blog to all things software related using Phix for code examples.
No comments:
Post a Comment