blog/another-imagemagick-use-case-process-oscilloscope-screenshots/another-imagemagick-use-case-process-oscilloscope-screenshots.md (4688B)
1 %% 2 title: "Another ImageMagick Use Case: Process Oscilloscope Screenshots" 3 date: "28-Aug-2026" 4 %% 5 6 # Another ImageMagick Use Case: Process Oscilloscope Screenshots 7 8 It's been a while since the last post (time flies, right?), a lot has happened 9 but recently I bought a portable oscilloscope, the OWON HDS25S (2CH, 25 MHz, 250 10 MSa/s, 8 kSa memory depth), maybe I will talk about it in a future post, but in 11 this one I want to talk about another use case I found for ImageMagick: process 12 oscilloscope screenshots to change the dark color scheme to a lighter one, 13 making it suitable for reports and if desired, for printing. 14 15 <div class="centered-img"> 16 <img style="width: 38%" src="hds25s.png" alt="OWON HDS25s"> 17 </div> 18 19 Of course, ImageMagick has an infinite number of uses: converting images from 20 one format to another, compressing images, applying filters, etc. But with these 21 posts, I focus on those uses that are more complex or specific to a particular 22 use case. 23 24 So, even though I recently bought the oscilloscope, I've already used it 25 extensively for assignments and lab reports. In particular, I found the 26 oscilloscope's screenshot feature very useful for reports. I also like that two 27 screenshots fit nicely side by side on a PDF page because of the screen's 4:3 28 aspect ratio. 29 30 <div class="side-by-side"> 31 <img src="sine_250.png" alt="Sine of frecuency 250 Hz"> 32 <img src="sine_637.png" alt="Sine with frequency 637 Hz"> 33 </div> 34 35 As seen in the pictures above, the screenshots are clear and look nice, but when 36 using them in reports, for my personal taste, they look better with a lighter 37 color scheme. This also makes sense if the report needs to be printed, as it 38 uses much less ink since there is no need to print the background. 39 40 To convert the screenshots from a dark to a light color scheme, I created a 41 shell script that applies a series of ImageMagick filters to the input file. 42 Part of the resulting shell script can be seen below. 43 44 ```shell 45 WIDTH=$(magick "$INPUT" -format '%w' info:) 46 HEIGHT=$(magick "$INPUT" -format '%h' info:) 47 TRIG_X=$((WIDTH * 975 / 1000)) 48 49 magick "$INPUT" -negate -colorspace Gray \ 50 +sigmoidal-contrast 8x65% \ 51 -level 20%,90% gray.png 52 53 magick "$INPUT" -alpha off -fuzz 5% \ 54 -fill transparent +opaque '#F81C00' \ 55 -fill '#ED0000' -opaque '#F81C00' \ 56 red_mask.png 57 58 magick "$INPUT" -alpha off -fuzz 5% \ 59 -fill transparent +opaque '#00FC00' \ 60 -fill '#007A3D' -opaque '#00FC00' \ 61 green_mask.png 62 63 magick "$INPUT" -alpha off -fuzz 5% \ 64 -fill transparent +opaque '#68C4F0' \ 65 -fill '#FC0000' -opaque '#68C4F0' \ 66 -region "$((WIDTH-TRIG_X))x${HEIGHT}+${TRIG_X}+0" \ 67 -fill "#FF6900" -opaque '#FC0000' \ 68 +region blue_mask.png 69 70 magick "$INPUT" -alpha off -fuzz 5% \ 71 -fill transparent +opaque '#F8E400' \ 72 -fill '#005FFF' -opaque '#F8E400' \ 73 -region "$((WIDTH-TRIG_X))x${HEIGHT}+${TRIG_X}+0" \ 74 -fill "#FF6900" -opaque '#005FFF' \ 75 +region yellow_mask.png 76 77 magick "$INPUT" -alpha off -fuzz 5% \ 78 -fill transparent +opaque '#F87C20' \ 79 -fill "#FF6900" -opaque '#F87C20' \ 80 orange_mask.png 81 82 magick "$INPUT" -alpha off -fuzz 5% \ 83 -fill transparent +opaque '#10F8F0' \ 84 -fill '#FF00FF' -opaque '#10F8F0' \ 85 cyan_mask.png 86 87 magick gray.png -colorspace sRGB \ 88 red_mask.png -compose Over -composite \ 89 blue_mask.png -compose Over -composite \ 90 yellow_mask.png -compose Over -composite \ 91 green_mask.png -compose Over -composite \ 92 orange_mask.png -compose Over -composite \ 93 cyan_mask.png -compose Over -composite \ 94 "$OUTPUT" 95 ``` 96 97 The script works, by creating a color-inverted greyscale version of the input 98 image and saving it as `gray.png`. Then, for the main colors used by the 99 interface: red, blue, green, orange, cyan and yellow, it creates a mask in which 100 only that particular color appears, while the rest of the colors are made 101 transparent. It then replaces that color with the desired new color. For 102 example, for channel one's yellow `#F8E400`, `yellow_mask.png` is created with 103 the yellow color replaced with blue `#005FFF`. 104 105 At the end, all the masks are combined on top of the previously created inverted 106 greyscale image, resulting in the final image shown below. 107 108 <div class="centered-img"> 109 <img src="./sine_250_light.png" alt="OWON HDS25s"> 110 </div> 111 112 It is true that simply inverting the image would have been enough, but I think 113 it was worth the effort to write the script, given that the colors can be 114 specified arbitrarily and the final result is better.
