How to smooth a binary matrix around the breakpoint?

1 view (last 30 days)
I have two matrices Xa and Xb and create an index matrix Y = Xa>Xb
Y has zeros and ones. Each row and each column has at most one jump from 0 to 1 (all the ones are toward the lower-right corner of Y).
Instead of having abrupt jumps from 0 to 1, I'd like to smooth out those jumps in a very particular way:
In the 1-D case, an example would be:
Xa-Xb = [-5 -4 -1 5 8];
Y = [ 0 0 0 1 1];
Z = [ 0 0 1/3 1 1];
where Z is my smoothed matrix. To get 1/3 I split up the range between -1 and 5 into -1 to 2 and 2 to 5, and assign the first half to -1. Thus, 2/3 of this range is positive and should have gotten a 1. Since the range to the left of -1 is negative anyway, the value assigned to -1 should be 0.5*2/3 = 1/3.
Is there a very fast way to this operation for 2D matrices?

Answers (1)

Image Analyst
Image Analyst on 14 Sep 2013
Use conv() for 1-D and conv2() for 2-D matrices.
  5 Comments
Image Analyst
Image Analyst on 15 Sep 2013
Edited: Image Analyst on 15 Sep 2013
I see no reason why it should be 1/3. Explain why. What if your edge occurs in a long one, like [0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]? What would you want the last 0 or first 1 to be replaced with in that case? And explain why. Tell me exactly why you think you want to do this unusual thing. Binary matrices or images are almost never turned back into floating point matrices and smoothed. I can't thin of any reason why that would be necessary off the top of my head. Usually a binary matrix is the last step in something like masking or segmentation. I suppose it could be done in masking to do anti-aliasing but in that case you'd have a 0.5 not a 0.3333.
Tintin Milou
Tintin Milou on 15 Sep 2013
It's an application in economics. I'm discretizing a state space. Agents differ along two dimensions: wealth and productivity. Depending on their wealth and productivity level they become either workers (if the wage exceeds entrepreneurial profits) or entrepreneurs (else). It's a binary choice. I solve the agents' problem for a grid of productivity and wealth levels. Then, I aggregate across grid points (using integrals) to obtain the aggregate number of workers / entrepreneurs (that's what I'm eventually interested in). As a result, grid points proxy for some neighboring points that are not on the grid. This becomes problematic around the threshold, where agents switch from being a worker to being an entrepreneur. Small changes in how I set the grid affect the aggregate outcome (depending on whether I set a grid point just below or above the threshold). Of course, I could make the grid very very fine in that region to circumvent the problem, but that would be too time-consuming. Instead I wish to do a linear approximation. If Profits-Wage = [-5 -4 -1 5 8], then the first three grid points feature workers, while the next two feature entrepreneurs. However, grid point number 3 is very close to the threshold. In a continuous, linear world, agents with characteristics halfway between grid point 3 and 4, would be entrepreneurs (profit - wage = 2). Since grid point 3 proxies for 'grid point 2.5 to grid point 3.5', two-thirds of the agents between grid point 3 and 3.5 have profit-wage>0 and hence, are entrepreneurs. So, the value assigned to grid point 3 is not 100% workers, but only 50% (all workers on gridpoints 2.5-3) + 50%*1/3 (workers on gridpoints 3-3.17) = 66.67%, or: 33.33% workers.
Sorry for the long explanation.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!