-
1. Re: Find Visual Centre of an image
Mattmcquiff Aug 21, 2013 8:41 AM (in response to Mattmcquiff)the nearest I think I could get,
Copy to clipboard the entire layer
Crop the vertical by half, with anchor point bottom centre,
Trim based on transparent pixels
From this you should have the centre point of the bottom half of the image, then some how replace from the infomation in the clipboard.....
-
2. Re: Find Visual Centre of an image
Michael L Hale Aug 21, 2013 11:40 AM (in response to Mattmcquiff)Is the part that throws off the centering always at the top of the image? Is the necklace on a layer with a mask?
-
3. Re: Find Visual Centre of an image
Mattmcquiff Aug 21, 2013 3:12 PM (in response to Michael L Hale)Yes it's always the top half of the image.
In terms of of layers from top to bottom.
Main Image
BACKGROUND
Original image (hidden)
The main image holding the necklace isn't a masked layer but can easily be one if that makes it easier.
-
4. Re: Find Visual Centre of an image
timuric Aug 21, 2013 3:30 PM (in response to Mattmcquiff)Can you post your psd? To understand better what are possible solutions.
-
5. Re: Find Visual Centre of an image
Michael L Hale Aug 21, 2013 4:00 PM (in response to Mattmcquiff)The main image holding the necklace isn't a masked layer but can easily be one if that makes it easier.
If the layer doesn't have a mask how does the layer's transparency help center the image? Even if you trim the transparent areas where the black border would be the bottom of the image is still off center because of the extra white on one side.
-
6. Re: Find Visual Centre of an image
Mattmcquiff Aug 21, 2013 11:36 PM (in response to Michael L Hale)The Background layer is filled white and I hide it along with the layer original image and then trim based on transparent pixels.
-
-
8. Re: Find Visual Centre of an image
Michael L Hale Aug 22, 2013 9:27 AM (in response to Mattmcquiff)This works with the sample image.
if(app.documents.length>0){ var white = new SolidColor(); white.rgb.hexValue = 'FFFFFF'; var doc = app.activeDocument; var defaultRulerUnits = app.preferences.rulerUnits; app.preferences.rulerUnits = Units.PIXELS; var docWidth = doc.width.value; var docHeight = doc.height.value; doc.activeLayer = doc.layers[0]; loadLayerTransparencyToSelection(); doc.selection.select([[0,docHeight/2],[docWidth,docHeight/2],[docWidth,docHeight],[0,docHeight]],SelectionType.INTERSECT); var necklaceWidth = doc.selection.bounds[2]-doc.selection.bounds[0]; doc.selection.deselect(); doc.activeLayer.translate(Math.abs(docWidth-necklaceWidth),0); doc.revealAll(); selectLayerBelow(); doc.selection.selectAll(); doc.selection.fill(white); doc.selection.deselect(); app.preferences.rulerUnits = defaultRulerUnits; } function loadLayerTransparencyToSelection() { var desc = new ActionDescriptor(); var ref = new ActionReference(); ref.putProperty( charIDToTypeID('Chnl'), charIDToTypeID('fsel') ); desc.putReference( charIDToTypeID('null'), ref ); var ref = new ActionReference(); ref.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('Trsp') ); desc.putReference( charIDToTypeID('T '), ref ); executeAction( charIDToTypeID('setd'), desc, DialogModes.NO ); }; function selectLayerBelow(){ var desc = new ActionDescriptor(); var ref = new ActionReference(); ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Bckw" ) ); desc.putReference( charIDToTypeID( "null" ), ref ); desc.putBoolean( charIDToTypeID( "MkVs" ), false ); executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO ); } -
9. Re: Find Visual Centre of an image
Mattmcquiff Aug 29, 2013 8:55 AM (in response to Michael L Hale)Sorry, just been in receipt of the new CC!
I've run the script on the same file and it works well, run on another not so well. I don't think there is substatial difference to the last one to cause it to work but here is the new sample.
I made sure I had erased around it so that there were no un erased pixels. but no joy.
Many Thanks
Matt
-
10. Re: Find Visual Centre of an image
Michael L Hale Aug 29, 2013 10:30 AM (in response to Mattmcquiff)Yes, there is a difference between the images. The script I posted doesn't really find the visual center of the image. All it does is center the widest part of the bottom half of the layer. It excludes the top half because that area is not symmetrical. To 'visually center' the width of the necklace the bottom half needs to be symmetrical. It was in your first sample and is not in this second sample.
I would be worried that any 'fix' to correct for this image would only apply to this or similar images and not work for all the images you need to center.
-
11. Re: Find Visual Centre of an image
Mattmcquiff Aug 30, 2013 4:28 AM (in response to Michael L Hale)I'm just trying to break it down as the item is very similar. But I relise how if they are wrong then it simply won't work.
Actually discecting it to work in applescript form but stuck trying to load the selection.
tell application id "com.adobe.photoshop"
tell current document
--set {height:originalHeight, width:originalWidth} to it
load selection from channel "Main Image Transparency"
end tell
end tell
Result:
error "Adobe Photoshop CC got an error: Can’t get selection of current document." number -1728 from selection of current document
-
12. Re: Find Visual Centre of an image
Michael L Hale Aug 30, 2013 7:34 AM (in response to Mattmcquiff)I can not help with Applescript other than suggest you use the do javascript command to load the layer's transparency.
It may improve the centering if you divide the bottom half into 3 or 4 sections, find the center of each of those selections, then use the median of the centers.


