Photoshop - Auto align images into a grid - plugins

Is there a script/plugin/action available that will automatically align several images into a grid style layout e.g. wookmark ?
I am desperately in need of something to automate this, as a weekly project I have to arrange about 40 thumbnails into a PSD.

Using JavaScript...
You can define a selection using an array of coordinate points like so:
var x = 0;
var y = 0;
var w = thumbnailDoc.width; // width of thumbnail document
var h = thumbnailDoc.height; // height of thumbnail document
var sel = [ // Define a rectangle of coordinate points
[x, y], // moving clockwise from top-left corner of rectangle
[x + w, y],
[x + w, y + h],
[x, y + h],
[x, y] //back to start
];
var doc = app.documents.add(200, 200, 72) // create new document (width, height, resolution)
doc.selection.select(sel); // make a selection using the array of coordinates
doc.paste(true) // paste the contents of the clipboard
// pass in the boolean 'true' to make it paste into the selection
So all you have to do is loop through all the pictures, resize them to thumbnails if you haven't already, copy to the clipboard, then paste into the selection on the working document. Increment your x,y coordinates as you go and you're strolling.

Related

how to copy a part of a raw image

I want to copy selected part of a raw image to another image
I get start and end position as percentage and by that I can calculate the start and end position in width
how can I copy that selected part to another raw image?
Assuming it's a Texture2D, you can do the following:
Calculate A texture start/end X (dX)
Create a new Texture2D (B), sized as dX and full Y
Call A.GetPixels()
Iterate on array copying pixels to new texture
Apply on new texture
Pseudo code:
var aPixels = aTexture.GetPixels();
var bWidth = endX - startX;
var bTexture = new Texture2D(bWidth, endY);
var bPixels = bTexture.GetPixels();
for (int x = startX; x < endX; x++)
{
for (int y = 0; y < endY; y++)
{
var aIndex = x + y * A.width;
var bIndex = (x - startX) + y * bWidth;
bPixels[bIndex] = aPixels[aIndex];
}
}
bTexture.Apply();
Note that my code quite possibly won't work; as I'm typing this on a mobile phone.
Usually, Image Processing is an expensive process for CPUs, so I don't recommend it in Unity,
But anyway, For your image and in this special case, I think you can crop your image by changing the Size and Offset of texture in material.
Update:
This is an example of what I mentioned:
You can calculate Tile and Offset based on the dragged mouse position on Texture. (Check Here)
I found this.
you can set start coordinates and width and height to GetPixels();
void Start () {
public Texture2D mTexture;
Color[] c = mTexture.GetPixels (startX, startY, width, height);
Texture2D m2Texture = new Texture2D (width, height);
m2Texture.SetPixels (c);
m2Texture.Apply ();
gameObject.GetComponent<MeshRenderer> ().material.mainTexture = m2Texture;
}
```

loop over array matrix matlab

I am detecting circles in an image. I return circle radii and X,Y of the axis. I know how to crop 1 circle no problem with formula:
X-radius, Y-radius, width=2*r,height=2*r using imcrop.
My problem is when I get returned more than 1 circle.
I get returned circle radii in an array radiiarray.
I get returned circle centers in centarray.
When i disp(centarray), It looks like this:
146.4930 144.4943
610.0317 142.1734
When I check size(centarray) and disp it i get:
2 2
So I understand first column is X and second is Y axis values. So first circle center would be 146,144.
I made a loop that works for only 1 circle. "-------" is where I'm unsure what to use to get:
note: radius = r
1st circle)
X = centarray(1)-r;
Y = centarray(3)-r;
Width =2*r;
Width =2*r;
2nd circle)
X = centarray(2);
Y = centarray(4);
Width =2*r;
Width =2*r;
How would I modify the "------" parts for my code? I also would like that if there are 3+ circles the loop would work as Im getting sometimes up to 9 circles from an image.
B = imread('p5.tif');
centarray = [];
centarray = [centarray,centers];
radiiarray = [];
radiiarray = [radiiarray,radii];
for j=1:length(radiiarray)
x = centarray((------))-radiiarray(j); %X value to crop
y = centarray((------))-radiiarray(j); %Y value to crop
width = 2*radiiarray(j); %WIDTH
height = 2*radiiarray(j); %HEIGHT
K = imcrop(B, [x y width height]);
end
My full code, which doesnt work, as I realized why when i saw the way values are stored...:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DETECT + GET X Y WIDTH HEIGHT OF CIRCLES
I = imread('p5.tif');
subplot(2,2,1);imshow(I);title('Original Image');
%sharpen edges
B = imsharpen(I);
subplot(2,2,2);imshow(B);title('sharpened edges');
%find circles
Img = im2bw(B(:,:,3));
minRad = 20;
maxRad = 90;
[centers, radii] = imfindcircles(Img, [minRad maxRad], ...
'ObjectPolarity','bright','sensitivity',0.84);
imagesc(Img);
viscircles(centers, radii,'Color','green');
%nuber of circles found
%arrays to store values for radii and centers
centarray = [];
centarray = [centarray,centers];
radiiarray = [];
radiiarray = [radiiarray,radii];
sc = size(centarray);
disp(sc)
disp(centarray)
disp(radiiarray)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%CROP USING VALUE FROM ARRAYS NUMBER OF TIMES THERE ARE CENTERS(number of
%circles)
for j=1:length(radiiarray)
x = centarray((2*j)-1)-radiiarray(j); %X value to crop
y = centarray((2*j))-radiiarray(j); %Y value to crop
width = 2*radiiarray(j); %WIDTH
height = 2*radiiarray(j); %HEIGHT
disp(x)
disp(y)
disp(centarray)
%crop using values
K = imcrop(B, [x y width height]);
%togray
gray = rgb2gray(K);
subplot(2,2,3);imshow(K);title('cropped before bw');
Icorrected = imtophat(gray, strel('disk', 15));
%to black and white
black = im2bw(Icorrected);
subplot(2,2,4);imshow(black);title('sharpened edges');
%read
results = ocr(black);
number = results.Text;
%display value
disp(number)
end
Any help on how to create this kind of loop is appreciated as I just have no more ideas or cant find answer to this..
EDIT
SOLUTION
Hi, answer is to treat matrix as 2 dimensional.
for j=1:length(radiiarray)
x=centarray(j,1)
y=centarray(j,2)
width = radiiarray(j)
height = radiiarray(j)
end
as j increases values update correctly now.
answer is to treat matrix as 2 dimensional.
for j=1:length(radiiarray)
x=centarray(j,1)
y=centarray(j,2)
width = radiiarray(j)
height = radiiarray(j)
end
as j increases values update correctly now.
Thanks for #beaker for his comment! Thats why I figured it out

EaselJS shape x,y properties confusion

I generate a 4x4 grid of squares with below code. They all draw in correct position, rows and columns, on canvas on stage.update(). But the x,y coordinates for all sixteen of them on inspection are 0,0. Why? Does each shape has it's own x,y coordinate system? If so, if I get a handle to a shape, how do I determine where it was drawn originally onto the canvas?
The EaselJS documentation is silent on the topic ;-). Maybe you had to know Flash.
var stage = new createjs.Stage("demoCanvas");
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
var square = new createjs.Shape();
square.graphics.drawRect(i*100, j*100, 100, 100);
console.log("Created square + square.x + "," + square.y);
stage.addChild(square);
}
}
You are drawing the graphics at the coordinates you want, instead of drawing them at 0,0, and moving them using x/y coordinates. If you don't set the x/y yourself, it will be 0. EaselJS does not infer the x/y or width/height based on the graphics content (more info).
Here is an updated fiddle where the graphics are all drawn at [0,0], and then positioned using x/y instead: http://jsfiddle.net/0o63ty96/
Relevant code:
square.graphics.beginStroke("red").drawRect(0,0,100,100);
square.x = i * 100;
square.y = j * 100;

Make a circle inside a matrix in Matlab

I want to make a circle inside a matrix. For example; Make a matrix of some dimension, let's say ones(200,200) and then select its circle's x and y co-ordinates and change the color of these selected pixels and then show the image using imshow(img). As showing in the picture. Is it possible?
OR
Can I change this ploting code to picture for using the circle functionality?
radius = 5;
centerX = 20;
centerY = 30;
viscircles([centerX, centerY], radius);
axis square;
You can use meshgrid to create a grid of x and y coordinates and then use the equation of the circle to check whether each x/y pair is within the circle or not. This will yield a logical result which can be displayed as an image
[x,y] = meshgrid(1:200, 1:200);
isinside = (x - centerX).^2 + (y - centerY).^2 <= radius^2;
imshow(isinside);
If you simply want the outline of the circle, you can apply a convolution to the resulting binary mask to decrease it's size and then subtract out the circle to yield only the outline
shrunk = ~conv2(double(~isinside), ones(3), 'same');
outline = isinside - shrunk;
imshow(outline)
If you have the Image Processing Toolbox, you can use bwperim to yield the binary outline
outline = bwperim(isinside);
imshow(outline);
Update
If you want to change the colors shown above, you can either invert outline and isinside before displaying
isinside = ~isinside;
outline = ~outline;
imshow(isinside)
imshow(outline)
Or you can invert the colormap
imshow(isinside)
colormap(gca, flipud(gray))

create cylinders in 3D volumetric data

I'm trying to create a dataset of raw volumetric data consisting of geometrical shapes. The point is to use volume ray casting to project them in 2D but first I want to create the volume manually.
The geometry is consisting of one cylinder that is in the middle of the volume, along the Z axis and 2 smaller cylinders that are around the first one, deriving from rotations around the axes.
Here is my function so far:
function cyl= createCylinders(a, b, c, rad1, h1, rad2, h2)
% a : data width
% b : data height
% c : data depth
% rad1: radius of the big center cylinder
% rad2: radius of the smaller cylinders
% h1: height of the big center cylinder
% h2: height of the smaller cylinders
[Y X Z] =meshgrid(1:a,1:b,1:c); %matlab saves in a different order so X must be Y
centerX = a/2;
centerY = b/2;
centerZ = c/2;
theta = 0; %around y
fi = pi/4; %around x
% First cylinder
cyl = zeros(a,b,c);
% create for infinite height
R = sqrt((X-centerX).^2 + (Y-centerY).^2);
startZ = ceil(c/2) - floor(h1/2);
endZ = startZ + h1 - 1;
% then trim it to height = h1
temp = zeros(a,b,h1);
temp( R(:,:,startZ:endZ)<rad1 ) = 255;
cyl(:,:,startZ:endZ) = temp;
% Second cylinder
cyl2 = zeros(a,b,c);
A = (X-centerX)*cos(theta) + (Y-centerY)*sin(theta)*sin(fi) + (Z-centerZ)*cos(fi)*sin(theta);
B = (Y-centerY)*cos(fi) - (Z-centerZ)*sin(fi);
% create again for infinite height
R2 = sqrt(A.^2+B.^2);
cyl2(R2<rad2) = 255;
%then use 2 planes to trim outside of the limits
N = [ cos(fi)*sin(theta) -sin(fi) cos(fi)*cos(theta) ];
P = (rad2).*N + [ centerX centerY centerZ];
T = (X-P(1))*N(1) + (Y-P(2))*N(2) + (Z-P(3))*N(3);
cyl2(T<0) = 0;
P = (rad2+h2).*N + [ centerX centerY centerZ];
T = (X-P(1))*N(1) + (Y-P(2))*N(2) + (Z-P(3))*N(3);
cyl2(T>0) = 0;
% Third cylinder
% ...
cyl = cyl + cyl2;
cyl = uint8(round(cyl));
% ...
The concept is that the first cylinder is created and then "cut" according to the z-axis value, to define its height. The other cylinder is created using the relation A2 + B 2 = R2 where A and B are rotated accordingly using the rotation matrices only around x and y axes, using Ry(θ)Rx(φ) as described here.
Until now everything seems to be working, because I have implemented code (tested that it works well) to display the projection and the cylinders seem to have correct rotation when they are not "trimmed" from infinite height.
I calculate N which is the vector [0 0 1] aka z-axis rotated in the same way as the cylinder. Then I find two points P of the same distances that I want the cylinder's edges to be and calculate the plane equations T according to that points and normal vector. Lastly, I trim according to that equality. Or at least that's what I think I'm doing, because after the trimming I usually don't get anything (every value is zero). Or, the best thing I could get when I was experimenting was cylinders trimmed, but the planes of the top and bottom where not oriented well.
I would appreciate any help or corrections at my code, because I've been looking at the geometry equations and I can't find where the mistake is.
Edit:
This is a quick screenshot of the object I'm trying to create. NOTE that the cylinders are opaque in the volume data, all the inside is considered as homogeneous material.
I think instead of:
T = (X-P(1))*N(1) + (Y-P(2))*N(2) + (Z-P(3))*N(3);
you should try the following at both places:
T = (X-P(1)) + (Y-P(2)) + (Z-P(3));
Multiplying by N is to account for the direction of the axis of the 2nd cylinder which you have already done just above that step.