Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Sub Pixel Accuracy From Non Integer Values

Subject: Sub Pixel Accuracy From Non Integer Values

From: omegayen

Date: 16 Dec, 2010 19:38:05

Message: 1 of 7

I have an interesting problem I have been working on that I won't go into all of the details with right now but can if there is some interest.

I have developed an algorithm that will allow a user to specify an integer value number of cells. What then happens is all of those circles are packed into a large circle which is fit precisely within a square.

Hence the large circle has a radius that can be related to pixel values although can be any decimal number specified. Consequently the small circles radii (which are all the same) can be then computed so they all roughly touch each other when they are packed into this circle.

Hence I can compute the x and y coordinates of the center of each small circle and can also compute of course a bounding box which I know the coordinates of of each small circle., based on the small circle radius.

What I would like to do is to relate these non integer x and y coordinates of each small circle to integer values so that I can easily manipulate them in MATLAB since MATLAB does not allow for non integer index values. Hence what I would like to do is take the corresponding intensity value of each circle and put it in a corresponding pixel. Currently what I have been working with is that one small circle approximately has a width and height of 1.25 pixels. Hence multiple pixels can lie in each small circle.

So I was thinking some sort of sub pixel accuracy conversion needs to occur. For example it possible that a pixel can be in multiple small circles and hence that pixel would need to somehow take into account the intensity values of the small circles it is in with some sort of a weighting factor.

I know this is a bit involved but if anyone has any thoughts it would be much appreciated.

Subject: Sub Pixel Accuracy From Non Integer Values

From: Sean de

Date: 16 Dec, 2010 19:46:20

Message: 2 of 7

"omegayen " <omegayen@ameritech.net> wrote in message <iedpqt$32r$1@fred.mathworks.com>...
> I have an interesting problem I have been working on that I won't go into all of the details with right now but can if there is some interest.
>
> I have developed an algorithm that will allow a user to specify an integer value number of cells. What then happens is all of those circles are packed into a large circle which is fit precisely within a square.
>
> Hence the large circle has a radius that can be related to pixel values although can be any decimal number specified. Consequently the small circles radii (which are all the same) can be then computed so they all roughly touch each other when they are packed into this circle.
>
> Hence I can compute the x and y coordinates of the center of each small circle and can also compute of course a bounding box which I know the coordinates of of each small circle., based on the small circle radius.
>
> What I would like to do is to relate these non integer x and y coordinates of each small circle to integer values so that I can easily manipulate them in MATLAB since MATLAB does not allow for non integer index values. Hence what I would like to do is take the corresponding intensity value of each circle and put it in a corresponding pixel. Currently what I have been working with is that one small circle approximately has a width and height of 1.25 pixels. Hence multiple pixels can lie in each small circle.
>
> So I was thinking some sort of sub pixel accuracy conversion needs to occur. For example it possible that a pixel can be in multiple small circles and hence that pixel would need to somehow take into account the intensity values of the small circles it is in with some sort of a weighting factor.
>
> I know this is a bit involved but if anyone has any thoughts it would be much appreciated.

Pictures would help I think. Why don't you just use INTERP2 to scale to your desired sub-pixel accuracy?

Subject: Sub Pixel Accuracy From Non Integer Values

From: ImageAnalyst

Date: 16 Dec, 2010 20:27:30

Message: 3 of 7

You have a square, and inside that is a large circle. Okay, I got
that. But then you start suddenly talking about small circles packed
into the large circle. And pixels which I guess are squares inside
the large and small circles. Makes my head swim. I'm like Sean - I
need a picture. And a definition of "relate" and what you're actually
trying to accomplish (why you *need* sub pixel accuracy). And also
explain what "the intensity value of each circle" means exactly (is it
the circle intensity values, or the pixel values, and is the circle
solid or just a perimeter).

Subject: Sub Pixel Accuracy From Non Integer Values

From: omegayen

Date: 17 Dec, 2010 21:27:05

Message: 4 of 7

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <c4a200ff-f522-4da0-be8a-28601f4890b9@o14g2000prn.googlegroups.com>...
> You have a square, and inside that is a large circle. Okay, I got
> that. But then you start suddenly talking about small circles packed
> into the large circle. And pixels which I guess are squares inside
> the large and small circles. Makes my head swim. I'm like Sean - I
> need a picture. And a definition of "relate" and what you're actually
> trying to accomplish (why you *need* sub pixel accuracy). And also
> explain what "the intensity value of each circle" means exactly (is it
> the circle intensity values, or the pixel values, and is the circle
> solid or just a perimeter).

Thanks for the comments so far

Here are some pictures to help illustrate

http://img574.imageshack.us/i/4by4noncoloredgrid21cir.jpg/

http://img651.imageshack.us/i/4by4coloredgrid21circle.jpg/

The first image shows a 4 by 4 pixel grid with each square pixel having a red border. Thus these pixels I refer to are these small red squares.

All of these little red squares (pixels) are in one large 4 by 4 pixel square. Inside of this 4 by 4 pixel square you cant fit a circle (in green).

Then I have some algorithm that will attempt to pack circles in this large circle (in green). These small circles have a black border and there are 20 of them in these images.

I know the center coordinate (x, y) of each small circle. Which you can tell from these images is non integer. Each small circle has a uniform intensity value.

What I want to do is fill in those 16 small red squares (pixels) with an appropriate intensity value based on the small circles contained inside of it. As you can tell in some cases 1 small red square (pixel) has multiple small circles inside. This is where the sub-pixel accuracy I was referring to comes in. I would like to be able to fill in those 16 small red squares based on some sort of average that takes into account how much of each small circle is in that pixel and the intensity value of that small circle.

The second image I refer to shows those 16 small red squares (pixels) filled in with an intensity value but it is not based on any sub-pixel accuracy and seeing how much of each small circle is contained within the small red square. It is instead just a brute force round of the x,y coordinates of a small circle nearby and then filling in that small red square the small circles intensity value.

This is just a simple example, in fact I am working with many more pixels and small circles.

Subject: Sub Pixel Accuracy From Non Integer Values

From: Sean de

Date: 17 Dec, 2010 21:55:30

Message: 5 of 7

"omegayen " <omegayen@ameritech.net> wrote in message <iegkj9$r00$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <c4a200ff-f522-4da0-be8a-28601f4890b9@o14g2000prn.googlegroups.com>...
> > You have a square, and inside that is a large circle. Okay, I got
> > that. But then you start suddenly talking about small circles packed
> > into the large circle. And pixels which I guess are squares inside
> > the large and small circles. Makes my head swim. I'm like Sean - I
> > need a picture. And a definition of "relate" and what you're actually
> > trying to accomplish (why you *need* sub pixel accuracy). And also
> > explain what "the intensity value of each circle" means exactly (is it
> > the circle intensity values, or the pixel values, and is the circle
> > solid or just a perimeter).
>
> Thanks for the comments so far
>
> Here are some pictures to help illustrate
>
> http://img574.imageshack.us/i/4by4noncoloredgrid21cir.jpg/
>
> http://img651.imageshack.us/i/4by4coloredgrid21circle.jpg/
>
> The first image shows a 4 by 4 pixel grid with each square pixel having a red border. Thus these pixels I refer to are these small red squares.
>
> All of these little red squares (pixels) are in one large 4 by 4 pixel square. Inside of this 4 by 4 pixel square you cant fit a circle (in green).
>
> Then I have some algorithm that will attempt to pack circles in this large circle (in green). These small circles have a black border and there are 20 of them in these images.
>
> I know the center coordinate (x, y) of each small circle. Which you can tell from these images is non integer. Each small circle has a uniform intensity value.
>
> What I want to do is fill in those 16 small red squares (pixels) with an appropriate intensity value based on the small circles contained inside of it. As you can tell in some cases 1 small red square (pixel) has multiple small circles inside. This is where the sub-pixel accuracy I was referring to comes in. I would like to be able to fill in those 16 small red squares based on some sort of average that takes into account how much of each small circle is in that pixel and the intensity value of that small circle.
>
> The second image I refer to shows those 16 small red squares (pixels) filled in with an intensity value but it is not based on any sub-pixel accuracy and seeing how much of each small circle is contained within the small red square. It is instead just a brute force round of the x,y coordinates of a small circle nearby and then filling in that small red square the small circles intensity value.
>
> This is just a simple example, in fact I am working with many more pixels and small circles.


This isn't sub-pixel accuracy in the way it is typically though of (or at all). Typically the pixel is your resolution with sub-pixel accuracy being the variation between intensities. Since you have a lot of information beneath the this level, the "pixel" or red block is not your resolution and your resolution is actually much smaller.
Take a look at BLKPROC to find a mean value inside those blocks.

Subject: Sub Pixel Accuracy From Non Integer Values

From: omegayen

Date: 20 Dec, 2010 16:34:21

Message: 6 of 7

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <iegm8i$dud$1@fred.mathworks.com>...
> "omegayen " <omegayen@ameritech.net> wrote in message <iegkj9$r00$1@fred.mathworks.com>...
> > ImageAnalyst <imageanalyst@mailinator.com> wrote in message <c4a200ff-f522-4da0-be8a-28601f4890b9@o14g2000prn.googlegroups.com>...
> > > You have a square, and inside that is a large circle. Okay, I got
> > > that. But then you start suddenly talking about small circles packed
> > > into the large circle. And pixels which I guess are squares inside
> > > the large and small circles. Makes my head swim. I'm like Sean - I
> > > need a picture. And a definition of "relate" and what you're actually
> > > trying to accomplish (why you *need* sub pixel accuracy). And also
> > > explain what "the intensity value of each circle" means exactly (is it
> > > the circle intensity values, or the pixel values, and is the circle
> > > solid or just a perimeter).
> >
> > Thanks for the comments so far
> >
> > Here are some pictures to help illustrate
> >
> > http://img574.imageshack.us/i/4by4noncoloredgrid21cir.jpg/
> >
> > http://img651.imageshack.us/i/4by4coloredgrid21circle.jpg/
> >
> > The first image shows a 4 by 4 pixel grid with each square pixel having a red border. Thus these pixels I refer to are these small red squares.
> >
> > All of these little red squares (pixels) are in one large 4 by 4 pixel square. Inside of this 4 by 4 pixel square you cant fit a circle (in green).
> >
> > Then I have some algorithm that will attempt to pack circles in this large circle (in green). These small circles have a black border and there are 20 of them in these images.
> >
> > I know the center coordinate (x, y) of each small circle. Which you can tell from these images is non integer. Each small circle has a uniform intensity value.
> >
> > What I want to do is fill in those 16 small red squares (pixels) with an appropriate intensity value based on the small circles contained inside of it. As you can tell in some cases 1 small red square (pixel) has multiple small circles inside. This is where the sub-pixel accuracy I was referring to comes in. I would like to be able to fill in those 16 small red squares based on some sort of average that takes into account how much of each small circle is in that pixel and the intensity value of that small circle.
> >
> > The second image I refer to shows those 16 small red squares (pixels) filled in with an intensity value but it is not based on any sub-pixel accuracy and seeing how much of each small circle is contained within the small red square. It is instead just a brute force round of the x,y coordinates of a small circle nearby and then filling in that small red square the small circles intensity value.
> >
> > This is just a simple example, in fact I am working with many more pixels and small circles.
>
>
> This isn't sub-pixel accuracy in the way it is typically though of (or at all). Typically the pixel is your resolution with sub-pixel accuracy being the variation between intensities. Since you have a lot of information beneath the this level, the "pixel" or red block is not your resolution and your resolution is actually much smaller.
> Take a look at BLKPROC to find a mean value inside those blocks.

Okay thanks. BLKPROC looks like it could be useful although it requires a function as input.

I am not entirely sure how to code that function however. I have the center coordinates of each small circle and also know each small circles radius (which is the same).

Hence when a red line intersects a circle this would correspond to a circular segement of which there is a good discussion at http://mathworld.wolfram.com/CircularSegment.html

However in my case the circular segment can be cut in half. So does anyone have any insights into how to calculate the area for the circular segments in my case perhaps just demonstrating with one of the pixels (red square) as an example.

Subject: Sub Pixel Accuracy From Non Integer Values

From: ImageAnalyst

Date: 20 Dec, 2010 20:00:07

Message: 7 of 7

Not without doing a bunch or trigonometry, which (assuming you've
passed the 10th grade) you can do yourself. But I don't blame you for
looking around first - I'd do the same thing. But I assume you've
done that so it looks like you might be deriving it yourself. Unless
one of the mathematicians in this group decides to take it on as a
brain teaser, but I wouldn't wait around depending on that to happen.
Good luck. That's if you want to do it analytically.

If you want to do it numerically it might be easier. Just make up and
image, plop down your discs and grid lines, label and call
regionprops. But of course you'll have quantization error determined
by the resolution you've chosen for your image.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us