My answer was intended to help you find the optimal threshold to use.
You are trying to interpret it as a way to measure how good a given
threshold is. It turns out that the computations you did contain that
information, but my method is much faster than checking each individual
threshold.
The input I had assumed was a matrix of intensities ranging from 0 to
255. From this I computed a "score" for each threshold without
calculating any thresholded images. This is likely orders of magnitude
faster than running contigmd on many thresholded images.
The metric used for a threshold is essentially the length of the
diamond's boundary. It's the number of places where a 1 is next to a 0,
and minimizing it will tend to remove holes, which add to the boundary.
If you imagine the initial image as a grid of points, where each has
height equal to its intensity (like you would get with
('surface' plot img)), then a threshold can be represented as a
horizontal plane, and the value to be minimized is the number of grid
lines which it crosses.
That condition is independent of the horizontal position of the
endpoints of each grid line, and if we ignore that information, we find
each line spans some interval within the range 0-255 of possible
intensities. The threshold cuts that line if it lies within the
interval. So we want to count the number of intervals containing the
threshold.
To do that, the first step is to find all of the pairs of adjacent
intensities, which is performed by the function you used below. When
applied to a thresholded image containing only zeros and ones, there are
only four possible pairs. Making a histogram of these values like
freqcount does then gives four numbers:
> 0 0 1034
> 1 1 302
> 1 0 84
> 0 1 84
These are the number of pairs of adjacent zeros, ones, and zero-one
pairs in both directions. The sum of the last two numbers (i.e. 84+84)
is the value to be minimized, since it is the number of places where the
threshold left two adjacent pixels next to each other.
Marshall
On Tue, Jun 27, 2017 at 02:03:47PM -0400, Brian Schott wrote:
> Marshall,
>
> There are 2 images in this "conversation": im1 and im2.
> If I apply your code for finding pairs of adjacent pixels on these 2 images
> I get the following results. Can you elaborate on the meaning and
> meaningfulness of the results below, please?
>
> $((}. ,.&, }:) , (}."1 ,.&, }:"1))im1
> 1504 2
> freqcount=: (\: {:"1)@(~. ,. #/.~)
> freqcount((}. ,.&, }:) , (}."1 ,.&, }:"1))im1 NB. poor image
> 0 0 1034
> 1 1 302
> 1 0 84
> 0 1 84
> freqcount((}. ,.&, }:) , (}."1 ,.&, }:"1))im2 NB. better image
> 0 0 962
> 1 1 450
> 1 0 46
> 0 1 46
>
> Thank you,
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm