Image.Rectangle Crop

Scripts and programs to automate Astroart
Post Reply
User avatar
Morten Lerager
Posts: 69
Joined: 08 Oct 2021, 14:53
Location: Denmark

Image.Rectangle Crop

Post by Morten Lerager » 15 Nov 2021, 15:56

Hi' AA's
(Nothing about Alcoholic)
Trying to make it easy to crop to a known aspect ratio.
I can make a crop by the Image.crop (x1,y1,x2,y2)
But that's very "hard coded" (Inflexible)
Then we have the Image.Rectangle but as I read it, it's only for returning size, not for setting.
I want a macro to act like :
Make a Rectangle Selection
Press ^R
Read the coordinate and change them according to aspect ratio.
Then move the selection as normal ^ mouse
And then do a Crop.

So how to do that :?:
HEQ5 Pro 150PDS 60mm guide. Asiair.
Asi294mc. AA8.

Iver
Posts: 115
Joined: 08 Jan 2019, 04:32
Location: Monterey county, Ca.

Re: Image.Rectangle Crop

Post by Iver » 16 Nov 2021, 02:45

Hi Morten, open an image you want to crop then drag a rectangle the size and position you want. Next open define Macro and then use the slider to find Crop. Double click crop and name the macro. When you run that macro it will crop the image that is open or you can load the images you want cropped and they will all be cropped.
Iver

fabdev
Posts: 502
Joined: 03 Dec 2018, 21:43

Re: Image.Rectangle Crop

Post by fabdev » 16 Nov 2021, 04:03

Hi, may you explain the pass:
"Read the coordinate and change them according to aspect ratio" ?
What is the goal of the processing? Maybe there's a different way to do that.
Fabio.

User avatar
Morten Lerager
Posts: 69
Joined: 08 Oct 2021, 14:53
Location: Denmark

Re: Image.Rectangle Crop

Post by Morten Lerager » 16 Nov 2021, 17:05

Thank's Fabio
The goal is to crop in etc 3:2 format.
As I understand the crop as it is, I'll have to do the calc. every time. The macro is for simulate crop as we know it in PS or Gimp. Make a selection with giving aspect ration.

@Iver that way will only make the same crop every time.
Same as the Image.crop x1,x2,y1,y2
HEQ5 Pro 150PDS 60mm guide. Asiair.
Asi294mc. AA8.

fabdev
Posts: 502
Joined: 03 Dec 2018, 21:43

Re: Image.Rectangle Crop

Post by fabdev » 17 Nov 2021, 02:07

OK.
It's not possible to select a rectangle via scripts, but since usually a selection is centered around an object, this script could solve:
Select a point on the subject then:

Code: Select all

sizeX = 300
sizeY = 200
if Image.Points.Count <> 1 then
   Message("Please select a point")
   end
end if
cx = Image.GetPointX
cy = Image.GetPointY
x1 = cx - sizeX / 2
y1 = cy - sizeY / 2
x2 = x1 + sizeX - 1
y2 = y1 + sizeY - 1
Image.PrepareUndo
Image.Crop(x1, y1, x2, y2)
This could be modified to work on selected rectangles too, where cx, cy, and size are calculated from the active rectangle.

User avatar
Morten Lerager
Posts: 69
Joined: 08 Oct 2021, 14:53
Location: Denmark

Re: Image.Rectangle Crop

Post by Morten Lerager » 17 Nov 2021, 18:45

Thank's Fabio
I look into it and return with a solution.
HEQ5 Pro 150PDS 60mm guide. Asiair.
Asi294mc. AA8.

User avatar
Morten Lerager
Posts: 69
Joined: 08 Oct 2021, 14:53
Location: Denmark

Re: Image.Rectangle Crop

Post by Morten Lerager » 28 Nov 2021, 15:25

Hi'
I came up with this solution.
Not so smooth as i was aimed for. But it' works
The Crop will be in a Aspect Ratio of 3:2
Preselect a rectangle. The hight is used to calculate the crop width

' *** Aspect Ratio ***
' *** AstroArt 8 ***
' *** 28:11:21 Morten Lerager ***
' Make rectangle selection
' The Hight will be used for Calc. the size.
' So the width is Only for only for determination the center
AR=1.5 '=Aspect Ratio 3:2
x1 = Image.Rectangle.X1
y1 = Image.Rectangle.Y1
x2 = Image.Rectangle.X2
y2 = Image.Rectangle.Y2
if x1 = x2 then
print "Select rectangle with a Height to Crop before RUN"
end
end if
height=(y2-y1)
IF frac(height/2) = 0.5 Then
y2=y2+1
height=height+1
endif
HW=int(height*1.5/2)
xcen=(x2-x1)/2+x1
x1=xcen-HW
x2=xcen+HW

If x1<0 then
Print "X<0 out of border"
END
end if
If x2>Image.Width then
Print "X> Image Width out of border"
END
end if

Image.Points.Add(x1,y1)
Image.Points.Add(x2,y1)
Image.Points.Add(x2,y2)
Image.Points.Add(x1,y2)
Input "Do yot want to Crop at these four points Y/N ?", answer
IF answer <> "Y" and answer <> "y" then
Image.Points.Clear
Print "STOPPED"
END
end if
Image.Points.Clear
Image.PrepareUndo
Image.crop (x1,y1,x2,y2)
Image.Update
HEQ5 Pro 150PDS 60mm guide. Asiair.
Asi294mc. AA8.

fabdev
Posts: 502
Joined: 03 Dec 2018, 21:43

Re: Image.Rectangle Crop

Post by fabdev » 30 Nov 2021, 14:07

Thanks Morten, I confirm that in AA8 Service pack 1 there will be a script command to select rectangles.
Fabio.

User avatar
Morten Lerager
Posts: 69
Joined: 08 Oct 2021, 14:53
Location: Denmark

Re: Image.Rectangle Crop

Post by Morten Lerager » 30 Nov 2021, 18:32

Oh, thats greeat news Fabio, thank you.
i will be looking forward to it.
HEQ5 Pro 150PDS 60mm guide. Asiair.
Asi294mc. AA8.

Post Reply