View Issue Details

IDProjectCategoryView StatusLast Update
0001896CCdciel[All Projects] Generalpublic18-02-16 17:19
ReporterhanAssigned ToPatrick Chevalley 
PrioritylowSeverityfeatureReproducibilityhave not tried
Status resolvedResolutionfixed 
Product Version 
Target Version1.0Fixed in Version 
Summary0001896: Feature request: Tilt indication for image inspection
DescriptionAttached and below a proposed update of the procedure Tf_main.MeasureImage. It adds a tilt indication of the camera.

The routine extension is simple, It records the median values of four parts of the image taken. This give four new median values. It then find the best and worst median value = corner of the image. The tilt is indicated as % ratio between the best and worst corner median values. In addition as an graphical indication it draws an trapezium in the image based on the four median values.

There is some variation in images of the same series, so a tilt of maybe 20% looks normal but anything more indicates a camera mounting problem.

Was fun to make!

procedure Tf_main.MeasureImage(Sender: TObject); {measure the median HFD of the image and mark stars with a square proportional to HFD value}
 fitsX,fitsY,size,imageX,imageY,s,xxc,yyc,rc,fx,fy,nhfd,nhfd_top_left,nhfd_top_right,nhfd_bottom_left,nhfd_bottom_right,x1,x2,x3,x4,y1,y2,y3,y4 : integer;
 hfd1,star_fwhm, vmax,bg,bgdev,xc,yc,snr, median_top_left, median_top_right,median_bottom_left,median_bottom_right,median_worst,median_best,scale_factor : double;
 hfdlist, hfdlist_top_left,hfdlist_top_right,hfdlist_bottom_left,hfdlist_bottom_right :array of double;
 Saved_Cursor : TCursor;
 mess2 : string;
    overlap=2; {box overlap,results in 1 pixel overlap}

  if not fits.HeaderInfo.valid then exit;

  Saved_Cursor := Screen.Cursor;
  Screen.Cursor := crHourglass; { Show hourglass cursor since analysing will take some time}

  DrawImage; {draw clean image}

  imabmp.Canvas.Pen.Mode := pmMerge;
  imabmp.Canvas.Pen.width := 1;{thickness lines}
  imabmp.Canvas.Pen.Color := $FF;

  s:=14; {test image in boxes of size s*s}

  nhfd:=0;{set counters at zero}
  SetLength(hfdlist,0);{set array length to zero}

  for fy:=3 to ((img_Height) div s)-3 do { move test box with stepsize rs around}
    for fx:=3 to ((img_Width) div s)-3 do
      if ((vmax>fits.imagemax*0.1) {new bright star found}
           and (xxc>fitsX- round(s/2)) and (yyc>fitsY-round(s/2)) {prevent double detections in overlap area}
           and (not fits.double_star(rc, xxc,yyc)) ) {ignore double stars} then
           fits.GetHFD(xxc,yyc,rc,bg,bgdev,xc,yc,hfd1,star_fwhm,vmax,snr);{calculated HFD}

      if ((hfd1>0.8) and (hfd1<99)) then
        inc(nhfd); SetLength(hfdlist,nhfd); hfdlist[nhfd-1]:=hfd1; {set length to new number of elements and store hfd value}
        if ( (fitsX<(img_width div 2)) and (fitsY<(img_height div 2)) ) then begin inc(nhfd_bottom_left); SetLength(hfdlist_bottom_left,nhfd_bottom_left); hfdlist_bottom_left[nhfd_bottom_left-1]:=hfd1;end;{store corner HFD values}
        if ( (fitsX>(img_width div 2)) and (fitsY<(img_height div 2)) ) then begin inc(nhfd_bottom_right);SetLength(hfdlist_bottom_right,nhfd_bottom_right);hfdlist_bottom_right[nhfd_bottom_right-1]:=hfd1;end;
        if ( (fitsX<(img_width div 2)) and (fitsY>(img_height div 2)) ) then begin inc(nhfd_top_left); SetLength(hfdlist_top_left,nhfd_top_left); hfdlist_top_left[nhfd_top_left-1]:=hfd1;end;
        if ( (fitsX>(img_width div 2)) and (fitsY>(img_height div 2)) ) then begin inc(nhfd_top_right); SetLength(hfdlist_top_right,nhfd_top_right); hfdlist_top_right[nhfd_top_right-1]:=hfd1;end;

        size:=round(5*hfd1);{show a square 10 times larger the HFD for quick HFD evaluation in all corners}

        imabmp.Canvas.Rectangle(imageX-size,imageY-size, imageX+size, imageY+size);{indicate hfd with red square}
        imabmp.Canvas.textout(imageX+size,imageY+size,floattostrf(hfd1, ffgeneral, 2,1));{add hfd as text}
  if nhfd>0 then
    if ((nhfd_top_left>0) and (nhfd_top_right>0) and (nhfd_bottom_left>0) and (nhfd_bottom_right>0)) then {enough information for tilt calculation}

      median_best:=min(min(median_top_left, median_top_right),min(median_bottom_left,median_bottom_right));{find best corner}
      median_worst:=max(max(median_top_left, median_top_right),max(median_bottom_left,median_bottom_right));{find worst corner}

      x1:=round(-median_bottom_left*scale_factor+img_width/2);y1:=round(-median_bottom_left*scale_factor+img_height/2);{calculate coordinates counter clockwise}

      imabmp.Canvas.Pen.width := 2;{thickness lines}
      imabmp.Canvas.moveto(x1,y1);{draw trapezium}
      imabmp.Canvas.lineto(x2,y2);{draw trapezium}
      imabmp.Canvas.lineto(x3,y3);{draw trapezium}
      imabmp.Canvas.lineto(x4,y4);{draw trapezium}
      imabmp.Canvas.lineto(x1,y1);{draw trapezium}

      imabmp.Canvas.lineto(img_width div 2,img_height div 2);{draw diagonal}
      imabmp.Canvas.lineto(x2,y2);{draw diagonal}
      imabmp.Canvas.lineto(img_width div 2,img_height div 2);{draw diagonal}
      imabmp.Canvas.lineto(x3,y3);{draw diagonal}
      imabmp.Canvas.lineto(img_width div 2,img_height div 2);{draw diagonal}
      imabmp.Canvas.lineto(x4,y4);{draw diagonal}
      mess2:=' Tilt indication:'+inttostr(round(100*((median_worst/median_best)-1)))+'%';{estimate tilt value}
    NewMessage('Image median hfd='+formatfloat(f1,SMedian(hfdList))+ mess2);{median HFD and tilt indication}
    NewMessage('No star detected. Is the image focused and sufficiently exposed?');

  Screen.Cursor := saved_cursor;

TagsNo tags attached.



18-02-16 16:32


screen_shot.jpg (79,537 bytes)
screen_shot.jpg (79,537 bytes)


18-02-16 16:35

reporter   ~0004447

Attached test image and code. Somehow MantisBT can't handle two files at once.


18-02-16 16:40

reporter   ~0004448

Strange, can't upload rar or 7z archives. Try zip again with cropped image. (4,907,852 bytes)

Patrick Chevalley

18-02-16 17:19

administrator   ~0004449

Very good feature, thank you very much!
I try your test image and it work fine.
Also a few of my last images show only a 5% tilt, I am reassured but I will play with that on the next clear night.

I commit the change in revision 794.

This will be in version 0.9.24 I am preparing just now.

Mantis as a white list of file extension, I added rar and 7z now and also increase the file size limit to 50MB so there is less problem to upload images.

Issue History

Date Modified Username Field Change
18-02-16 16:32 han New Issue
18-02-16 16:32 han File Added: screen_shot.jpg
18-02-16 16:35 han Note Added: 0004447
18-02-16 16:40 han File Added:
18-02-16 16:40 han Note Added: 0004448
18-02-16 17:19 Patrick Chevalley Assigned To => Patrick Chevalley
18-02-16 17:19 Patrick Chevalley Status new => resolved
18-02-16 17:19 Patrick Chevalley Resolution open => fixed
18-02-16 17:19 Patrick Chevalley Target Version => 1.0
18-02-16 17:19 Patrick Chevalley Note Added: 0004449