patchGNU Octave - Patches: patch #9448, image package: new function...

 
 

patch #9448: image package: new function imfindcircles.m

Submitted by:  Hartmut <hardy>
Submitted on:  Wed 06 Sep 2017 09:04:35 PM UTC  
 
Category: Forge : new functionPriority: 5 - Normal
Status: DonePrivacy: Public
Assigned to: NoneOpen/Closed: Closed

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

(Jump to the original submission Jump to the original submission)

Mon 15 Jan 2018 07:52:24 PM UTC, comment #8:

OK.

I am sure that I have seen white lines with viscircles an hour ago. But now everything works fine for me as well, correct colors from viscircles. I don't know what I did wrong last time.

Thanks for reviewing and polishing this function, Carne!

Hartmut <hardy>
Mon 15 Jan 2018 07:23:06 PM UTC, comment #7:

> Alright. I've done some more testing of the modified version of imfindcircles. And it seems to still behave nicely. I think this new function is mostly ready for pushing to the repo.


Done

http://hg.code.sf.net/p/octave/image/rev/f3d64772b21a

http://hg.code.sf.net/p/octave/image/rev/fcf037d3421b

> * You could add some more "distortions" like staight lines, squares and salt&pepper noise to the data for the demo block. This shows the advanced capabilities of this circular Hough transform.


Ok. I added noise, a blurring filter, and a square.

> * There seems to be a bug in the new viscircles.m, at least I cannot get the EdgeColor option to work at all. For example the demo block in imfindcircles gives me white circles (even though the default color shoud be red as the figure title says) and the demo block in viscircles also gives me white circles (even though the code explicitly asks for black ones).


I can't reproduce it. I have tried with Octave 4.0, 4.2, and a ~1 month olf 4.2 with both gnuplot and qt graphics toolkit. I did found that the LineWidth option being ignored but that seems to be an issue with the line function.

Carnë Draug <carandraug>
Project Member
Mon 15 Jan 2018 06:22:57 PM UTC, comment #6:

Alright. I've done some more testing of the modified version of imfindcircles. And it seems to still behave nicely. I think this new function is mostly ready for pushing to the repo.

Some minor comments:

  • You could add some more "distortions" like staight lines, squares and salt&pepper noise to the data for the demo block. This shows the advanced capabilities of this circular Hough transform.
  • There seems to be a bug in the new viscircles.m, at least I cannot get the EdgeColor option to work at all. For example the demo block in imfindcircles gives me white circles (even though the default color shoud be red as the figure title says) and the demo block in viscircles also gives me white circles (even though the code explicitly asks for black ones).
Hartmut <hardy>
Mon 15 Jan 2018 02:31:10 PM UTC, comment #5:

> (Sorry, I didn't manage to leave comments directly in your bitbucket repo.)


Bitbucket only allows comments on commits. You can't comment on source files alone.

> * There is a typo somewhere: "directions late ron."


Found it and fixed now.

> * I think the function imhmax(f, h) can be fully deleted in the code of imfindcircles.
> * The function imregionalmax(img) can also be deleted inside the code of imfindcircles.


I will remove them when I rebase the commits. At the moment, they're branching from a commit where those functions don't exist.

> * The last section (visualize the found circles in the image) in the !demo code can be re-written much nicer now, because imviscircles is implemented. (It should turn into roughly a one-liner.)


Similarly, viscircles is not available on this head. I will adjust when I rebase. I am also thinking of also simplifying it by using phantom() to generate the test data. Like so:

> * Do the tests all still pass?


Yes.

Carnë Draug <carandraug>
Project Member
Fri 12 Jan 2018 08:59:26 PM UTC, comment #4:

I have only had the chance for a short look at your code changes, yet. Some things have popped to my eyes so far:
(Sorry, I didn't manage to leave comments directly in your bitbucket repo.)

  • There is a typo somewhere: "directions late ron."
  • I think the function imhmax(f, h) can be fully deleted in the code of imfindcircles.
  • The function imregionalmax(img) can also be deleted inside the code of imfindcircles.
  • The last section (visualize the found circles in the image) in the !demo code can be re-written much nicer now, because imviscircles is implemented. (It should turn into roughly a one-liner.)
  • Do the tests all still pass?
Hartmut <hardy>
Fri 12 Jan 2018 07:16:57 PM UTC, comment #3:

I have made a bunch of changes to the code with

https://bitbucket.org/carandraug/octave-image/commits/ebbdb577c767290764a186930e51b5e178ec72e8

the changes seem like a lot but the actual computations are pretty much the same. The main change that looks so difficult to interpret on a diff is the separation of the long function into subfunctions for:

  • the accumulation / voting
  • estimate centers from the accumulator
  • estimate radii

Order than hopefully making things clear, it also handles the destruction of no longer required varibales which should also make it use less memory. Other than the reordering of the code to split into subfunctions, the only main change was the non-initialization of the accumulator because it's initialized by accumuarray.

I have joined a bunch of assert blocks taht didn't actually checked the return values. If they are only being used to check that the function does not error, then %!test is enough

Let me know if you have any question on the changes I made. I will merge them if there's none.

Carnë Draug <carandraug>
Project Member
Wed 06 Dec 2017 09:13:50 PM UTC, comment #2:

I have improved the code according to Carne's suggestions on Bitbucket. The new version can be found here:

https://bitbucket.org/hgimpel/octave-image/commits/a3690a8e7dfef9d4be02ff984cb82c0b1fe126cc

and is also attached as an m-file (V2) to this report.

(file #42586)

Hartmut <hardy>
Sat 09 Sep 2017 07:49:37 PM UTC, comment #1:

The code from comment #0 works fine on it's own, now. But here is a list of possible code improvements, that can be done after code at other places has been changed:

  • As soon as imregionalmax.m can deal with float values (see bug #51724), then the subfunction imregionalmax() can be deleted from the code of imfindcircles.m
  • As soon as the function imhmax.m is implemented in the image package, the subfunction imhmax() can be deleted from the code of imfindcircles.m
  • As soon as imviscircles.m is implemented in the image package (see patch #9449), then the last part of the demo block in imfindcircles.m can be re-written much nicer.
Hartmut <hardy>
Wed 06 Sep 2017 09:04:35 PM UTC, original submission:

I have implemented the missing function "imfindcircles.m" for the image package.

This function finds circles in an image, using the circular Hough transform. It only implements the (default and better) algorithm "PhaseCode" of the two algorithms in the Matlab function.

The following papers and books were used for the implementation of this function:
(see source code for details)

  • for general information on the circle Hough transform and the basic algorithmic approach: E. R. Davies: "Computer & Machine Vision", Academic Press (2012), 4th edition, chapter 12 "Circle and Ellipse Detection"
  • for the 'phase code' algorithm to search for a radius range with just a 2-dimensional accumulator array: T. J. Artherton and D. J. Kerbyson: "Size invariant circle detection", Image and Vision Computing 17 (1999), p. 795-803.
  • for 'state of the art' peak finding in the circular Hough transform accumulator array: C. Zhang, F. Huber, M. Knop, F. A. Hamprecht: "Yest cell detection and segmentation in bright field microscopy", IEEE Int. Symp. Biomed. Imag. (ISBI), April 2014, p. 1267-1270.

You can find the new m-file on my bitbucket repository:
https://bitbucket.org/hgimpel/octave-image/commits/ddef18c9b0bdff710b3d140ae5866d4e1c7561b1

The file is on the default branch there, with the bookmark "new-imfindcircles" attached.

I will also add the function file (imfindcircles_V1.m) to this report.

I tried to make the function mostly Matlab compatible. I would say the results are of comparable quality as the Matlab results, but not identical. It includes several (Matlab compatible) tests.

I would be happy to hear comments or feedback on this.

Hartmut <hardy>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

Attached Files
file #42586:  imfindcircles_V2.m added by hardy (24KiB - text/x-objcsrc)
file #41747:  imfindcircles_V1.m added by hardy (24KiB - text/x-objcsrc)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by hardy (Submitted the item)
  • -email is unavailable- added by hardy
  • -email is unavailable- added by hardy
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 6 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 15 Jan 2018 07:23:06 PM UTCcarandraugStatusNone=>Done
      Open/ClosedOpen=>Closed
    Wed 06 Dec 2017 09:13:50 PM UTChardyAttached File-=>Added imfindcircles_V2.m, #42586
    Wed 06 Sep 2017 09:04:35 PM UTChardyAttached File-=>Added imfindcircles_V1.m, #41747
      Carbon-Copy-=>Added avinoam
      Carbon-Copy-=>Added carandraug

    Back to the top


    Powered by Savane 3.1-cleanup1