Problem using "clear outside" command


I’m looking at cells in a plate which moves around slightly as you go through a timelapse. Because of this movement, and the fact that the cells are clustered together, when I draw an ROI around a single cell and the plate moves slightly, the ROI ends up shifting away from the current cell and partly encroaching a neighboring cell. To address this, I tried drawing an ROI around a cell and then clearing everything outside the cell using “clear all”. Then I made a new ROI which surrounded not only the cell in its current position, but also any area where it might move throughout the timelapse. However, when I then go through the timelapse and the cell moves beyond the bounds of its original ROI, the pixel values of the area that the cell moves into stay white and don’t change, causing the cell to get cut off. What I’m looking for is a way to clear everything outside of an ROI, while still allowing the pixel values in the “cleared” area to change when the pixels in the part of the image that wasn’t “cleared” move into the part that was. Is there any way to do this?
Thanks for any help!
(ps. I didn’t have any luck with the image registration tools, which is why I’m trying to find another way to work around the cell movement.)


Yet the registration tools seem to be the appropriate choice, especially as the motion should be uniform for all cells in the plate. Did you try stackreg on a timelapse stack of images? Why did this not work?

If you want to contine the current path, rather than clear outside, you could move the ROI with the motion. Use the roiManager to store the rois for each time step and re-position the ROI center based on the center of gravity of your measurement. You can iterate moving the ROI toward the center of gravity of the current cell until the desired displacement is smaller than a threshold and use that position as starting position for the next time frame. Here is a snippet of code that uses an oval but the principle shoud work for any ROI; the displacement threshold here is arbitrarily set to 1.

function homeIn(A){
//verified to work on unscaled image (ie. in pixel coordinates)
	//home in on the center of gravity of an object
	//change coordinates A[1,2]to the center of gravity found in an A[0]-radius-sized circle around A[1,2]
		satisfied=(rx < 1);
	}while (!satisfied);


Thanks for the help. Splitting it up into different time frames is what I’ve been doing so far, but I didn’t realize I could automate that, so I’ll try it.