This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from PIL import Image | |
# Open a multichannel image | |
# In this example, an RGB image | |
fname = r"C:\Users\Conor\Downloads\PXL_20240304_174814563.MP.jpg" | |
im = Image.open(fname) | |
arr = np.array(im,dtype=np.uint8) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
seed(99) | |
N = 100 | |
x = runif(N) | |
noise = rnorm(N,mean=0,sd=0.1) | |
y_corr = 1*x + noise | |
y_nocorr = noise | |
rsq_corr = cor(x,y_corr) | |
rsq_nocorr = cor(x,y_nocorr) | |
plot(x,y_corr,xlim=c(0,1),ylim=c(-0.3,1.0),pch=16,xlab="x",ylab="y",cex.lab=1.55) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fpdf import FPDF | |
def makeGrid(w=210.0, h=297.0, nrow=5, ncol=4, outf="grid.pdf", grey = 220, dl=3, sl=2, lwd=0.2): | |
'''Writes a single page pdf of width w mm and height h mm (defaults are A4) with a nrow x ncol grid | |
traced out on it, to file outf. Grid is a thin line (thickness is lwd) coloured grey (default is very | |
light grey) with dashing specified by dash length dl and space length sl.''' | |
pdf = FPDF(orientation="P", unit="mm", format=(w,h)) | |
deltax = float(w)/ncol | |
deltay = float(h)/nrow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Plot wide data | |
test = data.frame(id=1:4,"A"=1:4,"B"=5:8,"C"=11:14) | |
# Plot original order | |
stripchart(test[,2:4]) | |
# Plot updated order | |
stripchart(test[,c("C","A","B")]) | |
# Plot long data | |
test2 = reshape(test,direction="long",varying=c("A","B","C"),v.names="Value",idvar=c("id"),timevar=c("Label"),times=c("A","B","C")) | |
# Plot original order |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A possible problem with freezing artefacts and correlations | |
# Need MASS library to sample from multivariate normal distribution (correlated datasets) | |
library(MASS) | |
R_good = matrix(c(0.55, 0.5, | |
0.5, 0.55), | |
nrow = 2, ncol = 2, byrow = TRUE) | |
R_bad = matrix(c(1, 0.5, | |
0.5, 1), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import time | |
from pathlib import Path | |
import os | |
cam = cv2.VideoCapture(1) | |
cam.set(3, 1920) | |
cam.set(4, 1080) | |
cv2.namedWindow("test") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random, numpy | |
def genGuess(N,W,H): | |
'''Generate sensible initial guess vector (random circle coordinates and radii)''' | |
z=numpy.zeros(3*N) | |
for i in xrange(0,N): | |
z[i*3]=random.random()*W | |
z[i*3+1]=random.random()*H | |
z[i*3+2]=0.001*min(W,H)+random.random()*(0.009*min(W,H)) | |
return(z) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from PIL import Image | |
import time | |
start = time.time() | |
# Find bounding box using numpy | |
# https://stackoverflow.com/questions/31400769/bounding-box-of-numpy-array | |
def bbox2(img): | |
rows = np.any(img, axis=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("MASS") | |
# Generate some synthetic (NPC-corrected) control data | |
N_ctrl = 666 | |
sigma_ctrl = matrix(c(2,3,3,6),nrow=2,ncol=2) | |
ctrl = data.frame(mvrnorm(n = N_ctrl, mu=c(5,7.5), sigma_ctrl),stringsAsFactors=FALSE) | |
colnames(ctrl) = c("VDAC1","NDUFB8") | |
# Generate some synthetic (NPC-corrected) patient data | |
# This dataset represents a patient with a nuclear-encoded defect in CI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(sp) | |
xvals = rnorm(1000) | |
yvals = rnorm(1000) | |
alpha = 0.1 | |
# Note you need to terminate by right-clicking and selecting "stop" | |
plot(xvals,yvals,xlab="x",ylab="y",pch=16,col=rgb(1,0,0,alpha)) | |
res = locator(n=4000, type="o") | |
selected = point.in.polygon(xvals,yvals,res$x,res$y)==1 |
NewerOlder