<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Joaquin A. Rodriguez Huerta on Medium]]></title>
        <description><![CDATA[Stories by Joaquin A. Rodriguez Huerta on Medium]]></description>
        <link>https://medium.com/@joaquinarodriguezhuerta?source=rss-dae711588b20------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*zosekUuH8TN-G9pb.</url>
            <title>Stories by Joaquin A. Rodriguez Huerta on Medium</title>
            <link>https://medium.com/@joaquinarodriguezhuerta?source=rss-dae711588b20------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 03:08:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@joaquinarodriguezhuerta/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Calculating DSLR camera gain with flat frames]]></title>
            <link>https://joaquinarodriguezhuerta.medium.com/calculating-dslr-camera-gain-with-flat-frames-04a9d9e7feeb?source=rss-dae711588b20------2</link>
            <guid isPermaLink="false">https://medium.com/p/04a9d9e7feeb</guid>
            <category><![CDATA[dslr-cameras]]></category>
            <category><![CDATA[astrophotography]]></category>
            <dc:creator><![CDATA[Joaquin A. Rodriguez Huerta]]></dc:creator>
            <pubDate>Sat, 10 Aug 2024 03:41:45 GMT</pubDate>
            <atom:updated>2024-08-10T03:41:45.312Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6xdOF9hMSEYOkobijqVS5A.png" /><figcaption>Heart Nebula</figcaption></figure><p>In the world of astrophotography, precision is everything. Every photon that strikes your camera’s sensor has travelled light-years across the universe, and how your camera handles these photons can make or break your final image. One of the key factors in this process is something called the <strong>gain</strong> of your camera, measured in <strong>electrons per ADU</strong>. Understanding and calculating this gain is essential for optimising your imaging and post-processing workflow.</p><h4>Understanding Gain: The Bridge Between Light and Digital Data</h4><p>When you capture an image, each pixel on your camera’s sensor collects photons, which are then converted into electrons. These electrons form the analog signal that the camera’s electronics convert into a digital value, known as an Analog-to-Digital Unit (ADU). The gain is a measure of how many electrons correspond to one ADU.</p><p>Conceptually, gain determines how sensitive your camera is to light and how it balances that sensitivity with the ability to capture a wide range of brightness levels, known as dynamic range. A low gain means more electrons are required to produce one ADU, resulting in a broader dynamic range but less sensitivity to faint light. Conversely, a high gain makes your camera more sensitive to low light but reduces the dynamic range, potentially leading to saturation in bright areas.</p><h4>A Practical Method to Calculate Gain Using Flat Frames</h4><p>To determine the gain of your DSLR, we can use a method that involves capturing flat frames with varying brightness. By subtracting pairs of these flat frames and analysing the resulting mean and variance, we can plot a relationship that allows us to calculate the gain using linear regression.</p><p>Here’s a step-by-step guide:</p><p><strong>Capture Flat Pairs with Varying Brightness:</strong></p><p>Capture several pairs of flat frames, each with slightly different brightness levels. For each pair, ensure that the change in brightness is small and controlled.</p><p><strong>Subtract Each Pair of Flat Frames:</strong></p><p>For each pair, subtract one frame from the other. This subtraction eliminates fixed-pattern noise and isolates the shot noise, which is related to the gain.</p><p><strong>Calculate the Mean and Variance:</strong></p><p>For each subtracted image, calculate the mean and variance. The mean represents the difference in light levels between the two frames, and the variance provides a measure of the noise in the image.</p><p><strong>Plot Mean vs. Variance and Perform Linear Regression:</strong></p><p>Plot the mean (adjusted to account for the subtraction process) against the variance. The slope of the resulting line, found through linear regression, will give you the reciprocal of the gain.</p><h4>The Mathematics Behind the Method</h4><p>The relationship between the mean and variance of the pixel values can be described by the equation:</p><p><strong><em>Variance (ADU) = 1/G ​× Mean (ADU)</em></strong></p><p>Where:</p><ul><li><strong>Variance(ADU):</strong> The variance of the subtracted flat frame.</li><li><strong>Mean(ADU):</strong> The mean of the subtracted flat frame, adjusted by multiplying by 2.</li><li><strong>G:</strong> The gain in electrons per ADU.</li></ul><p>The slope <strong><em>m</em></strong> of the plot Variance(ADU) vs Mean(ADU) provides:</p><p><strong><em>m =1 / G</em></strong></p><p>Thus, the gain G can be calculated as the reciprocal of <strong>m:</strong></p><p><strong><em>G = 1 / m</em></strong></p><p>The adjustment of the mean by a factor of 2 accounts for the fact that when subtracting two flat frames, the mean of the difference image is approximately twice the difference in the mean values of the original images. This adjustment ensures that the mean vs. variance plot accurately reflects the underlying signal and noise, leading to a precise calculation of the gain.</p><h4>Implementing the Calculation in Python</h4><p>To automate this process, you can use the following Python script. This script, when pointed to a folder containing your flat frames, will calculate the gain for you.</p><pre>import numpy as np<br>import os<br>from astropy.io import fits<br>import matplotlib.pyplot as plt<br>from sklearn.linear_model import LinearRegression<br><br>def load_fits_images(folder):<br>    flat_frames = []<br>    for filename in os.listdir(folder):<br>        if filename.endswith(&#39;.fits&#39;):<br>            filepath = os.path.join(folder, filename)<br>            flat_frames.append(fits.getdata(filepath))<br>    return flat_frames<br><br>def calculate_gain(flat_frames):<br>    means = []<br>    variances = []<br>    for i in range(0, len(flat_frames), 2):<br>        mean1 = np.mean(flat_frames[i])<br>        mean2 = np.mean(flat_frames[i + 1])<br>        <br>        diff_frame = flat_frames[i] - flat_frames[i + 1]<br>        variance = np.var(diff_frame)<br>        <br>        adjusted_mean = 2 * (mean1 + mean2) / 2<br>        <br>        means.append(adjusted_mean)<br>        variances.append(variance)<br><br>    means = np.array(means).reshape(-1, 1)<br>    variances = np.array(variances)<br>    reg = LinearRegression().fit(means, variances)<br>    slope = reg.coef_[0]<br>    gain = 1 / slope<br>    return gain, means, variances, reg<br><br>def plot_results(means, variances, reg):<br>    plt.scatter(means, variances, label=&#39;Data points&#39;)<br>    plt.plot(means, reg.predict(means), color=&#39;red&#39;, label=&#39;Linear fit&#39;)<br>    plt.xlabel(&#39;Mean (ADU)&#39;)<br>    plt.ylabel(&#39;Variance (ADU^2)&#39;)<br>    plt.legend()<br>    plt.title(&#39;Mean vs Variance&#39;)<br>    plt.show()<br><br>if __name__ == &quot;__main__&quot;:<br>    if len(sys.argv) != 2:<br>        print(&quot;Usage: python calculate_gain.py /path/to/your/flat/frames&quot;)<br>        sys.exit(1)<br>    <br>    folder = sys.argv[1]<br>    flat_frames = load_fits_images(folder)<br>    <br>    if len(flat_frames) % 2 != 0:<br>        print(&quot;Please ensure an even number of flat frames.&quot;)<br>    else:<br>        gain, means, variances, reg = calculate_gain(flat_frames)<br>        print(f&quot;Calculated Gain: {gain:.3f} electrons/ADU&quot;)<br>        plot_results(means, variances, reg)</pre><h4>Conclusion</h4><p>This method of calculating the gain in electrons per ADU using flat frames is a practical approach that allows you to understand the sensitivity and dynamic range of your camera sensor. By taking control of these parameters, you can optimise your astrophotography, ensuring that every photon captured by your camera is used to its fullest potential.</p><p>This knowledge not only enhances your ability to capture stunning images but also gives you a deeper understanding of the technical aspects of your equipment, empowering you to push the boundaries of what your camera can achieve under the night sky.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=04a9d9e7feeb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Digital proof of vaccination.]]></title>
            <link>https://joaquinarodriguezhuerta.medium.com/digital-proof-of-vaccination-7d82d08fcbf2?source=rss-dae711588b20------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d82d08fcbf2</guid>
            <category><![CDATA[vaccines]]></category>
            <category><![CDATA[covid19]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[canada]]></category>
            <category><![CDATA[quebec]]></category>
            <dc:creator><![CDATA[Joaquin A. Rodriguez Huerta]]></dc:creator>
            <pubDate>Sat, 15 May 2021 05:22:06 GMT</pubDate>
            <atom:updated>2021-05-15T14:22:11.300Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1_QIeN9nbhto3hchkxwhoQ.jpeg" /></figure><h3>How much of a trail are you leaving behind.</h3><p>I got vaccinated for COVID-19 a few days ago. A couple of days later I received an email saying I could now download my digital proof of vaccination. I proceeded to download it and I got a PDF with an huge QR code on it.</p><p>Lately there has been a lot of attention in the news about implementing some sort of vaccination password policy that would facilitate access to certain indoor activities. So the thought of having to scan your digital vaccination passport in order to be able to access a service has crossed my mind and is something I don’t really feel comfortable with. So far the Quebec government hasn’t made an official announcement about it, but I can’t help to think that without the correct legal frame it looks like it could be exploited as a tracking mechanism and as a form of discrimination.</p><p>This immediately spiked my curiosity about what sort of data was contained in the QR code. A quick search online revealed articles like this one:</p><p><a href="https://www.cbc.ca/news/canada/montreal/proof-vaccination-businesses-quebec-government-1.6021977">Roll out vaccine passport in time for summer, Quebec business group says | CBC News</a></p><p>Where you can find claims like this from Christian Dubé, the Quebec Health Minister:</p><pre>Health Minister Christian Dubé explained that the QR code — a scannable image that contains information — will be offered as a digital alternative to the paper proof of vaccination that is currently handed out.</pre><pre>The government will not, for the moment, make publicly available the algorithm needed to unlock the coded information, Dubé said.</pre><pre>That means businesses, or other non-governmental entities, won&#39;t be able to use the QR code to impose their own access restrictions.</pre><p>These claims don’t make sense to me. In order for the “proof of vaccination” to be useful it has to be based on some standard that different countries and institutions could use to validate it, or else it would be something only applicable to Quebec with nearly no value at all. More importantly you shouldn’t be able to forge it, or else its worthless.</p><p>I decided to scan my code and figure out what it contained. With the following commands:</p><pre>pdftoppm -png vaccination_proof.pdf | zbarimg -</pre><p>I scanned my QR code from the PDF I downloaded and got a string with the following format (this is not the real one as it would contain my personal info):</p><pre>shc:/8644062806234816154404863734597519242494422294016314733311955808235296850422617841724772581075641599494342432921825617786814576215687156447702785287027024651448152586652579318320456554429429761384067020786703017005146831368747015512031978540861802273643367354177277362760750862373377275574773037231229374110417823218121651785283294912325333821128563275290250064478461546478190851628007848456382781174655730326835011485507284502240614828544466843076115703492289419270883442299995825211980628328151014256957611453752887918854261793508895088254717137226348863199928326708174242326881154412016084854751275002362230268292693212445368364661822861796783587496909928758085117745280445905736710942907978212582666514402562828295237431637411138763921030746599983880474071531575694030252038892514812374442362772318603463674160341867799175155590429956858309774162762678843055330198324276467440476583466710279776883499212481878509933744496552377252102418367479734688638276480671918847443514394465854369453437712494108552552569368429880282552749571873449055646090355689047940611562584626026435854097114573518654</pre><p>To me this looked like some encoded data and the shc:/ prefix was a clue I could use to continue to investigate. A bit more Googling took me to this site:</p><p><a href="https://vci.org/">VCI</a></p><p>and further searching took me to this other one:</p><p><a href="https://smarthealth.cards/">SMART Health Cards Framework</a></p><p>And what do we have here, exactly what I was expecting to find. A documented standard definition for Electronic Health Record, and Immunisation Information for system vendors.</p><p>According to this document the long string I was looking at is just:</p><pre>A segment encoded with numeric mode consisting of the characters 0-9. Each character &quot;c&quot; of the JWS is converted into a sequence of two digits as by taking Ord(c)-45 and treating the result as a two-digit base ten number. For example, &#39;X&#39; is encoded as 43, since Ord(&#39;X&#39;) is 88, and 88-45 is 43. (The constant &quot;45&quot; appears here because it is the ordinal value of -, the lowest-valued character that can appear in a compact JWS. Subtracting 45 from the ordinal values of valid JWS characters produces a range between 00 and 99, ensuring that each character of the JWS can be represented in exactly two base-10 numeric digits.)</pre><p>This simple python line would decode that text and provide the underlying JSON web signature:</p><pre>jws_ = &#39;&#39;.join([chr(int(s[x:x+2]) + 45) for x in range(0, len(s), 2)])</pre><p>What we get back indeed looks like a JWS so I used the python-jose package and proceeded to decode it:</p><pre>from jose import jws<br>jws.get_unverified_header(jws_)</pre><pre>{&#39;kid&#39;: &#39;P_AFY9tFP8erKZhOlqXTeKLYVNtt4anX0mqvUrele28&#39;,<br> &#39;zip&#39;: &#39;DEF&#39;,<br> &#39;alg&#39;: &#39;ES256&#39;}</pre><pre>def_data = jws.get_unverified_claims(jws_)</pre><p>That looks promising! According to the documentation in def_data we now have a raw compressed blob of data. After a bit of fiddling around <a href="https://gist.github.com/tbarabosch/96f2afc0ddfae4ac0bb2a3e22f781b17">I found out</a> that in order to decode raw deflated data without headers you need to pass an -15 value on the offset, let’s try to that:</p><pre>import zlib<br>data = zlib.decompress(jws.get_unverified_claims(t), -15)</pre><p>and then tadaaa!:</p><pre>{<br>  &quot;iat&quot;: &quot;token_id&quot;,<br>  &quot;vc&quot;: {<br>    &quot;<a href="http://twitter.com/context">@context</a>&quot;: [<br>      &quot;<a href="https://www.w3.org/2018/credentials/v1">https://www.w3.org/2018/credentials/v1</a>&quot;<br>    ],<br>    &quot;type&quot;: [<br>      &quot;VerifiableCredential&quot;,<br>      &quot;<a href="https://smarthealth.cards/#health-card">https://smarthealth.cards#health-card</a>&quot;,<br>      &quot;<a href="https://smarthealth.cards/#immunization">https://smarthealth.cards#immunization</a>&quot;,<br>      &quot;<a href="https://smarthealth.cards/#covid19">https://smarthealth.cards#covid19</a>&quot;<br>    ],<br>    &quot;credentialSubject&quot;: {<br>      &quot;fhirVersion&quot;: &quot;1.0.2&quot;,<br>      &quot;fhirBundle&quot;: {<br>        &quot;resourceType&quot;: &quot;Bundle&quot;,<br>        &quot;type&quot;: &quot;Collection&quot;,<br>        &quot;entry&quot;: [<br>          {<br>            &quot;resource&quot;: {<br>              &quot;resourceType&quot;: &quot;Patient&quot;,<br>              &quot;name&quot;: [<br>                {<br>                  &quot;family&quot;: [<br>                    &quot;<strong>LAST_NAME</strong>&quot;<br>                  ],<br>                  &quot;given&quot;: [<br>                    &quot;<strong>FIRST_NAME</strong>&quot;<br>                  ]<br>                }<br>              ],<br>              &quot;birthDate&quot;: &quot;<strong>DATE_OF_BIRH</strong>&quot;,<br>              &quot;gender&quot;: &quot;<strong>GENDER</strong>&quot;<br>            }<br>          },<br>          {<br>            &quot;resource&quot;: {<br>              &quot;resourceType&quot;: &quot;Immunization&quot;,<br>              &quot;vaccineCode&quot;: {<br>                &quot;coding&quot;: [<br>                  {<br>                    &quot;system&quot;: &quot;<a href="http://hl7.org/fhir/sid/cvx">http://hl7.org/fhir/sid/cvx</a>&quot;,<br>                    &quot;code&quot;: &quot;208&quot;<br>                  }<br>                ]<br>              },<br>              &quot;patient&quot;: {<br>                &quot;reference&quot;: &quot;resource:0&quot;<br>              },<br>              &quot;lotNumber&quot;: &quot;<strong>VACCINE_LOT_NUMBER</strong>&quot;,<br>              &quot;status&quot;: &quot;Completed&quot;,<br>              &quot;occurrenceDateTime&quot;: &quot;2021-05-12T04:00:00+00:00&quot;,<br>              &quot;location&quot;: {<br>                &quot;reference&quot;: &quot;resource:0&quot;,<br>                &quot;display&quot;: &quot;<strong>VACCINATION_LOCATION</strong>&quot;<br>              },<br>              &quot;protocolApplied&quot;: {<br>                &quot;doseNumber&quot;: 1,<br>                &quot;targetDisease&quot;: {<br>                  &quot;coding&quot;: [<br>                    {<br>                      &quot;system&quot;: &quot;<a href="http://browser.ihtsdotools.org/?perspective=full&amp;conceptId1=840536004">http://browser.ihtsdotools.org/?perspective=full&amp;conceptId1=840536004</a>&quot;,<br>                      &quot;code&quot;: &quot;840536004&quot;<br>                    }<br>                  ]<br>                }<br>              },<br>              &quot;note&quot;: [<br>                {<br>                  &quot;text&quot;: &quot;PB COVID-19&quot;<br>                }<br>              ]<br>            }<br>          }<br>        ]<br>      }<br>    }<br>  }<br>}</pre><p>This token contains your full name, date of birth, the location and date where you vaccinated and the vaccine lot number.</p><p>This proves the health minister claims are false. It’s fairly easy for anyone with some basic programming skills and a bit of knowledge to decode this token and the information in it. Any developer in a few hours can develop an app that will scan this QR code as a verification step for admission to services and unless there is a proper legal framework it can be exploited to discriminate against people, that for reasons I’m not going to question, don’t want or can’t get vaccinated.</p><p>The other issue that this brings to light, is the fact that while this is not the most sensitive information in the world, is also something you don’t want to go spreading around, a trail of all the places you’ve been in the day. Imagine going to the mall and getting scanned at the entrance, or at every store, then at the restaurant, then at the movies. Each one of this vendors will have access to a piece of data that uniquely identifies you, your routines and potentially your preferences. This is enough to make me worry about how does the government of Canada, and particularly the government of Quebec, plans to guarantee the confidentiality of your data and the protection of your privacy. This information once scanned, could be replicated,kept and used without your consent.</p><p>A quick search here in Medium already reveals articles like this:</p><p><a href="https://ldstephens.me/scam-alert-spotting-phony-covid-19-vaccine-passport-apps-8449ffb0da86">Scam Alert: Spotting phony COVID-19 vaccine passport apps</a></p><p>Some food for thought, this vaccination passport is like that embarrassing photo we uploaded to the internet, once it’s scanned that data is out there and you can’t control who has access to it or how it gets used.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d82d08fcbf2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>