@@ -186,6 +186,8 @@ public void showHistogram(ImagePlus srcImp, ImageStatistics stats) {
186186 ip .resetRoi ();
187187 ip .fill ();
188188 ImageProcessor srcIP = srcImp .getProcessor ();
189+ if (frame == null )
190+ frame = HistogramPlot .getDefaultFrame ();
189191 drawHistogram (srcImp , ip , fixedRange , stats .histMin , stats .histMax );
190192 imp .updateAndDraw ();
191193 }
@@ -250,6 +252,8 @@ protected void drawHistogram(ImageProcessor ip, boolean fixedRange) {
250252 }
251253
252254 void drawHistogram (ImagePlus imp , ImageProcessor ip , boolean fixedRange , double xMin , double xMax ) {
255+ if (frame == null )
256+ frame = HistogramPlot .getDefaultFrame ();
253257 int x , y ;
254258 long maxCount2 = 0 ;
255259 int mode2 = 0 ;
@@ -269,8 +273,8 @@ void drawHistogram(ImagePlus imp, ImageProcessor ip, boolean fixedRange, double
269273 if ((newMaxCount >(maxCount2 * 2 )) && (maxCount2 != 0 ))
270274 newMaxCount = (int )(maxCount2 * 1.5 );
271275 if (logScale || IJ .shiftKeyDown () && !liveMode ())
272- drawLogPlot (yMax >0 ?yMax :newMaxCount , ip );
273- drawPlot (yMax >0 ?yMax :newMaxCount , ip );
276+ HistogramPlot . drawLogPlot (histogram , yMax >0 ?yMax :newMaxCount , ip , frame );
277+ HistogramPlot . drawPlot (histogram , yMax >0 ?yMax :newMaxCount , ip , frame , Color . BLACK );
274278 histogram [stats .mode ] = saveModalCount ;
275279 x = XMARGIN + 1 ;
276280 y = YMARGIN + HIST_HEIGHT + 2 ;
@@ -339,84 +343,6 @@ int scaleDown(ImageProcessor ip, double threshold) {
339343 else
340344 return 0 ;
341345 }
342-
343- void drawPlot (long maxCount , ImageProcessor ip ) {
344- if (maxCount ==0 ) maxCount = 1 ;
345- frame = new Rectangle (XMARGIN , YMARGIN , HIST_WIDTH , HIST_HEIGHT );
346- ip .drawRect (frame .x -1 , frame .y , frame .width +2 , frame .height +1 );
347- if (histogram .length ==256 ) {
348- double scale2 = HIST_WIDTH /256.0 ;
349- int barWidth = 1 ;
350- if (SCALE >1 ) barWidth =2 ;
351- if (SCALE >2 ) barWidth =3 ;
352- for (int i = 0 ; i < 256 ; i ++) {
353- int x =(int )(i *scale2 );
354- int y = (int )(((double )HIST_HEIGHT *(double )histogram [i ])/maxCount );
355- if (y >HIST_HEIGHT ) y = HIST_HEIGHT ;
356- for (int j = 0 ; j <barWidth ; j ++)
357- ip .drawLine (x +j +XMARGIN , YMARGIN +HIST_HEIGHT , x +j +XMARGIN , YMARGIN +HIST_HEIGHT -y );
358- }
359- } else if (histogram .length <=HIST_WIDTH ) {
360- int index , y ;
361- for (int i =0 ; i <HIST_WIDTH ; i ++) {
362- index = (int )(i *(double )histogram .length /HIST_WIDTH );
363- y = (int )(((double )HIST_HEIGHT *(double )histogram [index ])/maxCount );
364- if (y >HIST_HEIGHT ) y = HIST_HEIGHT ;
365- ip .drawLine (i +XMARGIN , YMARGIN +HIST_HEIGHT , i +XMARGIN , YMARGIN +HIST_HEIGHT -y );
366- }
367- } else {
368- double xscale = (double )HIST_WIDTH /histogram .length ;
369- for (int i =0 ; i <histogram .length ; i ++) {
370- long value = histogram [i ];
371- if (value >0L ) {
372- int y = (int )(((double )HIST_HEIGHT *(double )value )/maxCount );
373- if (y >HIST_HEIGHT ) y = HIST_HEIGHT ;
374- int x = (int )(i *xscale )+XMARGIN ;
375- ip .drawLine (x , YMARGIN +HIST_HEIGHT , x , YMARGIN +HIST_HEIGHT -y );
376- }
377- }
378- }
379- }
380-
381- void drawLogPlot (long maxCount , ImageProcessor ip ) {
382- frame = new Rectangle (XMARGIN , YMARGIN , HIST_WIDTH , HIST_HEIGHT );
383- ip .drawRect (frame .x -1 , frame .y , frame .width +2 , frame .height +1 );
384- double max = Math .log (maxCount );
385- ip .setColor (Color .gray );
386- if (histogram .length ==256 ) {
387- double scale2 = HIST_WIDTH /256.0 ;
388- int barWidth = 1 ;
389- if (SCALE >1 ) barWidth =2 ;
390- if (SCALE >2 ) barWidth =3 ;
391- for (int i =0 ; i < 256 ; i ++) {
392- int x =(int )(i *scale2 );
393- int y = histogram [i ]==0 ?0 :(int )(HIST_HEIGHT *Math .log (histogram [i ])/max );
394- if (y >HIST_HEIGHT ) y = HIST_HEIGHT ;
395- for (int j = 0 ; j <barWidth ; j ++)
396- ip .drawLine (x +j +XMARGIN , YMARGIN +HIST_HEIGHT , x +j +XMARGIN , YMARGIN +HIST_HEIGHT -y );
397- }
398- } else if (histogram .length <=HIST_WIDTH ) {
399- int index , y ;
400- for (int i = 0 ; i <HIST_WIDTH ; i ++) {
401- index = (int )(i *(double )histogram .length /HIST_WIDTH );
402- y = histogram [index ]==0 ?0 :(int )(HIST_HEIGHT *Math .log (histogram [index ])/max );
403- if (y >HIST_HEIGHT ) y = HIST_HEIGHT ;
404- ip .drawLine (i +XMARGIN , YMARGIN +HIST_HEIGHT , i +XMARGIN , YMARGIN +HIST_HEIGHT -y );
405- }
406- } else {
407- double xscale = (double )HIST_WIDTH /histogram .length ;
408- for (int i =0 ; i <histogram .length ; i ++) {
409- long value = histogram [i ];
410- if (value >0L ) {
411- int y = (int )(HIST_HEIGHT *Math .log (value )/max );
412- if (y >HIST_HEIGHT ) y = HIST_HEIGHT ;
413- int x = (int )(i *xscale )+XMARGIN ;
414- ip .drawLine (x , YMARGIN +HIST_HEIGHT , x , YMARGIN +HIST_HEIGHT -y );
415- }
416- }
417- }
418- ip .setColor (Color .black );
419- }
420346
421347 void drawText (ImageProcessor ip , int x , int y , boolean fixedRange ) {
422348 ip .setFont (font );
@@ -555,11 +481,9 @@ void replot() {
555481 ip .resetRoi ();
556482 ip .setColor (Color .black );
557483 ip .setLineWidth (1 );
558- if (logScale ) {
559- drawLogPlot (yMax >0 ?yMax :newMaxCount , ip );
560- drawPlot (yMax >0 ?yMax :newMaxCount , ip );
561- } else
562- drawPlot (yMax >0 ?yMax :newMaxCount , ip );
484+ if (logScale )
485+ HistogramPlot .drawLogPlot (histogram , yMax >0 ?yMax :newMaxCount , ip , frame );
486+ HistogramPlot .drawPlot (histogram , yMax >0 ?yMax :newMaxCount , ip , frame , Color .BLACK );
563487 this .imp .updateAndDraw ();
564488 }
565489
0 commit comments