ROI_Histogram.txt
// This script produces a live histogram of a given image.
// The region from which the histogram is computed may be resized and moved
// Finally, a normalized histogram will be shown
number width, height,top,left,bottom,right
ROI histRoi
// get the front image and its image display:
ImageDisplay imgDisp = GetFrontImage().ImageGetImageDisplay(0)
number ROIcount = ImageDisplayCountROIs(imgDisp);
// if no ROI exists, we will create one that spans the whole image:
if (ROIcount == 0) {
number height, width
// crate an empty Region of interest
histRoi = CreateROI();
// determine the size of the current image:
GetFrontImage().GetSize(width,height)
// set the size of the newly created ROI to the size of the whole image
ROISetRectangle(histRoi,0,0,height,width);
// assign the newly created ROI to the current image display:
ImageDisplayAddROI(imgDisp,histRoi);
}
// Give the ROI that we are using a name:
histRoi = imgDisp.ImageDisplayGetROI(0)
histRoi.ROISetLabel("Histogram ROI")
// Create a live histogram from this ROI (Note, that the last parameter
// defines the number of bins used for the histogram!)
image img = getfrontimage()
// We will use exactly as many bins as their are different values in the histogram
ROIGetRectangle(histRoi,top,left,bottom,right);
number bins = max(img[top,left,bottom,right])-min(img[top,left,bottom,right])
NewLiveHistogram(imgDisp,imgDisp.ImageDisplayGetROI(0),bins)
if (0) {
executeScriptFile("normalizeHistogram.s")
}