%%html
<script src="https://bits.csb.pitt.edu/asker.js/lib/asker.js"></script>
<style>
.reveal .highlight pre { font-size: 100%}
.reveal .slides>section>section.present { max-height: 100%; overflow-y: auto;}
</style>
<script>
$3Dmolpromise = new Promise((resolve, reject) => {
require(['https://3dmol.org/build/3Dmol.js'], function(){
resolve();});
});
require(['https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.2.2/Chart.js'], function(Ch){
Chart = Ch;
});
$('head').append('<link rel="stylesheet" href="https://bits.csb.pitt.edu/asker.js/themes/asker.default.css" />');
//the callback is provided a canvas object and data
var chartmaker = function(canvas, labels, data) {
var ctx = $(canvas).get(0).getContext("2d");
var dataset = {labels: labels,
datasets:[{
data: data,
backgroundColor: "rgba(150,64,150,0.5)",
fillColor: "rgba(150,64,150,0.8)",
}]};
var myBarChart = new Chart(ctx,{type:'bar',data:dataset,options:{legend: {display:false},
scales: {
yAxes: [{
ticks: {
min: 0,
}
}]}}});
};
$(".jp-InputArea .o:contains(html)").closest('.jp-InputArea').hide();
</script>
Images are composed of pixels (pix - picture, el - element).
In a grayscale image the pixel contains the intensity. Depending on the image format this may range from 0-1, 0-255, or be any floating point number.
In a color image a pixel is (usually) a triple (red,green,blue) of color values where each color intensity ranges from 0-255 (24-bit color).
%%html
<div id="imcol2" style="width: 500px"></div>
<script>
$('head').append('<link rel="stylesheet" href="https://bits.csb.pitt.edu/asker.js/themes/asker.default.css" />');
var divid = '#imcol2';
jQuery(divid).asker({
id: divid,
question: "Which contains the most information?",
answers: ['Gray','Color'],
extra: ['A grayscale image with floating point pixels', 'A color image where pixel values range from 0 to 255'],
server: "https://bits.csb.pitt.edu/asker.js/example/asker.cgi",
charter: chartmaker})
$(".jp-InputArea .o:contains(html)").closest('.jp-InputArea').hide();
</script>
It is very common for RGB color values to be represented in hexadecimal (e.g., HTML).
Hexadecimal number are usually indicated with a 0x
or #
prefix.
In hexadecimal, each digit can take one of 16 values (as opposed to 10). This means that each color can be represented with two digits (16*16 = 256)
Hex | Dec |
---|---|
A | 10 |
B | 11 |
C | 12 |
D | 13 |
E | 14 |
F | 15 |
%%html
<div id="hex1hs" style="width: 500px"></div>
<script>
$('head').append('<link rel="stylesheet" href="https://bits.csb.pitt.edu/asker.js/themes/asker.default.css" />');
var divid = '#hex1hs';
jQuery(divid).asker({
id: divid,
question: "What is the decimal value of 0x1F?",
answers: ['11','16','17','31','32'],
server: "https://bits.csb.pitt.edu/asker.js/example/asker.cgi",
charter: chartmaker})
$(".jp-InputArea .o:contains(html)").closest('.jp-InputArea').hide();
</script>
%%html
<div id="hex2hs" style="width: 500px"></div>
<script>
$('head').append('<link rel="stylesheet" href="https://bits.csb.pitt.edu/asker.js/themes/asker.default.css" />');
var divid = '#hex2hs';
jQuery(divid).asker({
id: divid,
question: "What is the decimal value of 0xfe?",
answers: ['15','32','127','254','255'],
server: "https://bits.csb.pitt.edu/asker.js/example/asker.cgi",
charter: chartmaker})
$(".jp-InputArea .o:contains(html)").closest('.jp-InputArea').hide();
</script>
%%html
<div id="hex3hs" style="width: 500px"></div>
<script>
$('head').append('<link rel="stylesheet" href="https://bits.csb.pitt.edu/asker.js/themes/asker.default.css" />');
var divid = '#hex3hs';
jQuery(divid).asker({
id: divid,
question: "What color is #ff00ff?",
answers: ['green','cyan','yellow','magenta','I failed art'],
server: "https://bits.csb.pitt.edu/asker.js/example/asker.cgi",
charter: chartmaker})
$(".jp-InputArea .o:contains(html)").closest('.jp-InputArea').hide();
</script>
print(0x1f, 0xfe)
31 254
<div style="color: #ff00ff">Hello</div>
The Python Imaging Library provides the ability to read, write an manipulate images in all the common formats. Some key modules:
Despite being a popular package, PIL development stopped in 2011 with no new releases since 2009.
Pillow is a fork of PIL that is fully backwards compatible and updated (and is what you are actually using rather than the original PIL).
!wget http://bits.csb.pitt.edu/images/image1.tif
--2023-06-27 07:51:40-- http://bits.csb.pitt.edu/images/image1.tif Resolving bits.csb.pitt.edu (bits.csb.pitt.edu)... 136.142.4.139 Connecting to bits.csb.pitt.edu (bits.csb.pitt.edu)|136.142.4.139|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 921814 (900K) [image/tiff] Saving to: ‘image1.tif.2’ image1.tif.2 100%[===================>] 900.21K --.-KB/s in 0.06s 2023-06-27 07:51:40 (15.4 MB/s) - ‘image1.tif.2’ saved [921814/921814]
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import numpy as np
%matplotlib inline
from PIL import Image
im = Image.open('image1.tif')
im