Skip to content

Instantly share code, notes, and snippets.

@miura
Created September 7, 2012 10:13
Show Gist options
  • Save miura/3664888 to your computer and use it in GitHub Desktop.
Save miura/3664888 to your computer and use it in GitHub Desktop.
kymograph drift corrector
// Shifts x position of signals in kymograph
// in respect to the drifts of egg edge position.
// Kota Miura + Masa Mori
//
// duplicate image (for getting the edge shift)
// gaussian blurr (sigma = 1)
//threshould
// registration in x direction
orgID = getImageID();
orgw = getWidth();
orgh = getHeight();
edgeposA = newArray(orgh);
for (j = 0; j < orgh; j++){
for (i = 0; i < orgw; i++){
// i = 52;
current = getPixel(i, j);
if (current == 0) {
//print("j:", j, " edge at: x=", i);
edgeposA[j] = i;
i = orgw;
}
}
}
Array.getStatistics(edgeposA, min, max, mean, stdDev);
print("min X", min);
print("max X", max);
newwidth = orgw + (max - min);
print("orginal w",orgw);
print("new w", newwidth);
newImage("shifted", "8-bit Black", newwidth, orgh, 1);
shiftedID = getImageID();
setBatchMode(true);
for (j = 0; j < orgh; j++){
shiftx = (max - edgeposA[j]);
for (i = 0; i < orgw; i++){
selectImage(orgID);
curpix = getPixel(i, j);
selectImage(shiftedID);
newx = i + shiftx; // this is the shift
setPixel(newx, j, curpix);
}
//print("Row:", j);
}
setBatchMode("exit and display");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment