YOUR ACCOUNT

Login or Register to post new topics or replies
hd8fdkd
NAO

Posts: 57
Filters: 10
Is there way to get the size and center coordinates of selection area?

I want to scale selection area without moving its center coordinates.
In addition, I want to get selection area's width and height pixels.
  Details E-Mail
Sphinx.
Filter Optimizer

Posts: 1750
Filters: 39
The selection must be same size as the image loaded. If you use Transform > Scale component, just set the XY Anchor to "Image Bounds", then 0.5,0.5 will be the center, and you can set any scale you want..
  Details E-Mail
hd8fdkd
NAO

Posts: 57
Filters: 10
Quote
Sphinx. wrote:
If you use Transform > Scale component, just set the XY Anchor to "Image Bounds", then 0.5,0.5 will be the center, and you can set any scale you want..


Sphinx, thank you for your reply.

In the Selection component, selected area is white square and unselected is black.
I wanted to scale white square (selected area) while keeping the original center coordinates.

I tried your method, but scale component applied to center of whole image.
(Scale component's parameter set the XY Anchor to "Image Bounds".
And origin X and origin Y set to 0.5.)

  Details E-Mail
Sphinx.
Filter Optimizer

Posts: 1750
Filters: 39
Oh! That's a whole different story!

There is no simple way to do that, because you only have information about the whole selection map as such available. Selection data can also be gradual (i.e. graytones).

What you need here is some sort of autotrim method that gives you the bounding rect of non zero selection samples. This is somewhat complicated to figure out when you work in a procedural rendering context..

Maybe it would be better to go at the problem from another perspective: what is your overall idea / goal here?
  Details E-Mail
hd8fdkd
NAO

Posts: 57
Filters: 10
Quote
Sphinx. wrote:
There is no simple way to do that, because you only have information about the whole selection map as such available. Selection data can also be gradual (i.e. graytones).

What you need here is some sort of autotrim method that gives you the bounding rect of non zero selection samples. This is somewhat complicated to figure out when you work in a procedural rendering context..

Maybe it would be better to go at the problem from another perspective: what is your overall idea / goal here?


I think that selection size and center information is useful for creation of new filters.
It is also helpful for updating existing filters.

For example, my filter "Stamp Maker" needs selection.
And this filter uses Frame components to make frame of stamp.
If I could get the selection size, I would reduce the margin between selection and frame.



I tried two things.

First, I tried to get these value by using "for loop".
(from 0 to 1, and step is 1 pixel)

ex.
Code
for i=0, 1, 1/SIZE do
   for j=0, 1, 1/SIZE do
      if get_sample_grayscale(i, j, SOURCE) == 1 then
         ...
      end
   end
end


But this code was too heavy and I couldn't get the result which I wanted.

Next, I used Blur component as scaling tool.
But this was too difficult for me to got the actual value.(ex.twice the width of selection)
  Details E-Mail
Sphinx.
Filter Optimizer

Posts: 1750
Filters: 39
Yes, a script is currently the only way to search down the bounding rect, and it can be done in a fairly optimal way IF we just didn't have that darn initialization overhead issue...

But even with that problem, you could optimize the search using this method.

Basically you perform the search inside the initialization section. The search must be performed in two steps:

1. search from top,left and forth to first encounter of a non zero sample (or the sample value of the top, left coordinate). At first encounter break the loop.

2. like above, but search from bottom, right and back instead.

you can output the values through r,g,b,a (top, left, bottom, right).

Btw..alternatively to your blur attempt, try using maximum or median instead of a blur...
  Details E-Mail
hd8fdkd
NAO

Posts: 57
Filters: 10
Quote
Sphinx. wrote:
Basically you perform the search inside the initialization section. The search must be performed in two steps:

1. search from top,left and forth to first encounter of a non zero sample (or the sample value of the top, left coordinate). At first encounter break the loop.

2. like above, but search from bottom, right and back instead.


Thanks to your advice, I could scale selection without moving center.
But code is very heavy.
Additionally, the width and height of selection area is slightly different from original.(few pixels)


Quote
Sphinx. wrote:
Btw..alternatively to your blur attempt, try using maximum or median instead of a blur...


I tried using Maximum component.
Radius control minimum is 0.01.
When the value set to 0.01, each edge increase 4 pixels.(when whole image size is 512 x 512)
I think detailed control is difficult.
  Details E-Mail
hd8fdkd
NAO

Posts: 57
Filters: 10
Sphinx, thanks anyway.
I will try these approachs again until another approach will be found.
  Details E-Mail
ThreeDee
Lost in Space

Posts: 1672
Filters: 112
A thought on this matter: Not the prettiest of solutions, but you could blur the selection image with directional blur horizontally for the vertical values and vertically for horizontal values (with motion blur component set to radius 100, directional 100, angle 0 or 90, not gaussian). Then perform the seach for non-zero values along x and y-axis from the edges on in. This way you'd only need to seach one row of pixels in each direction. I assume this would be faster than a purely script-based solution.
  Details E-Mail
hd8fdkd
NAO

Posts: 57
Filters: 10
ThreeDee, thank you for your reply.

Quote
ThreeDee wrote:
A thought on this matter: Not the prettiest of solutions, but you could blur the selection image with directional blur horizontally for the vertical values and vertically for horizontal values (with motion blur component set to radius 100, directional 100, angle 0 or 90, not gaussian). Then perform the seach for non-zero values along x and y-axis from the edges on in. This way you'd only need to seach one row of pixels in each direction. I assume this would be faster than a purely script-based solution.


You're amazing !
Now I can get the value of selection area width, height and center coordinates.

I used "Motion" blur instead of "Directional" one.
Because there is no "Directional Blur" Component.
Except it, I used your method.

If selection area has very long edge, it may need more steps below.
"Directional Blur" >>> "Threshold" >>> "Directional Blur"...

I'm going to continue to improve. Thanks.
  Details E-Mail

Join Our Community!

Filter Forge has a thriving, vibrant, knowledgeable user community. Feel free to join us and have fun!

33,711 Registered Users
+18 new in 30 days!

153,533 Posts
+31 new in 30 days!

15,348 Topics
+73 new in year!

Create an Account

Online Users Last minute:

28 unregistered users.