Can Photoshop guide lines' coordinates be programmatically retrieved from a psd file? - coordinates

I am curious if guide line coordinates (x coordinates actually) can be retrieved from a psd file.
Basically, let's say, I want to read the file from any programming language environment or open it using something that will provide me with the guide coordinates.
For clarity, I am talking about these lines:

Don't know about Java but you can do that easily with Javascript. This script will alert coordinates for all the guides of the active document in default Photoshop units:
var myGuides = [];
for (var i = 0; i < activeDocument.guides.length; i++) {
myGuides.push(activeDocument.guides[i].coordinate);
}
alert(myGuides);
So you can use values from myGuides for whatever reasons you need.

Related

Rename multi-frame dicom images

I have a dicom file that contains 110 images and their names are random. I am trying to rename them according to their SliceLocations (n) and rewrite them with the dcm extension, i.e., n(1).dcm, n(2).dcm, …
Any suggestions would be appreciated.
I tried
image_list=dir('*.dcm');
for i=1:110
img=dicomread(image_list);
imgHdr = dicominfo(image_list(i).name);
for j = size(img,4);
dicomwrite(img(:,:,:,j),['n(' int2str(j) ').dcm'],imgHdr,'CreateMode','Copy');
end
end
Slice location (0020,1041) is an optional attribute for image plane module. There is no guarantee that tag will have any value. Your best option is to use the Image Position (Patient) (0020, 0032) attribute. This will have x, y, and z coordinates of the upper left hand corner (center of the first voxel transmitted) of the image. See DICOM standard PS 3.3 - 2011 (PDF), Annex C.7.6.2.1, for further explanation.
NOTE: This answer applies to "frames," not "slices." The two are apparently different things for DICOM files.
One convenient option, if you don't need exactly the naming scheme in your question, is to use the 'MultiframeSingleFile' option in the dicomwrite function:
X = dicomread('MultiFrameFile.dcm');
dicomwrite(X,'n.dcm','MultiframeSingleFile',false);
This will produce files named 'n_01.dcm', 'n_02.dcm', ...
Otherwise you can use a simple for loop in conjunction with int2str:
X = dicomread('MultiFrameFile.dcm');
for i = size(X,4);
dicomwrite(X(:,:,:,i),['n(' int2str(i) ').dcm']);
end

Setting Pixels in Cocos2d-js - how to?

My goal is to write directly to pixels in a texture/sprite, to be able to update the game's details.
I was successful in doing this in Cocos2d-x with C++ (sample code below). The question is, "How can I do the equivalent in Javascript?"
//C++ WORKS:
board_texture= *sprite->getTexture();
// initialize pixels (array of GLubyte)
for (i=0 ; i<num_pix; i++){
pixels[i] = (GLubyte) 0;
}
// editing colors at specific positions:
pixels[i]=(GLubyte) 255; // r
pixels[i+1]=(GLubyte) 0; // g
pixels[i+2]=(GLubyte) 0;// b
pixels[i+3]=(GLubyte) 255; // a
board_texture.updateWithData(pixels,0,0,board_w,board_h);
sprite->setTexture(&board_texture);
This runs extremely fast on an iPad updating a 400x400 texture easily at 60FPS.
I've looked at Cocos2d-JS, however, and can find NO equivalent working functions for "updateWithData". I was able to get the texture2D into a local variable, but can find no way to update it's pixels (yet)
//JS does NOT work
var t;
t= this.map_sprite.getTexture(); // OK
// but does NOT allow me to updateWithData
t.setTexture(pixels) // fails, with Invalid Native Format. What's the proper format then?
Why? Cocos2d's developers are saying C++ is not supported in the future as much as Javascript (Cocos2d-js), as evidenced by the lack of JS support in the Cocos IDE. So, since I'm just starting out, I figured, I should do it in JS, not C++.

Matlab: How to interact with a graph to define a range via GUIs

I'm currently trying to make a GUI that will allow a user to select a range of x-values, limited to a set of predefined "markers" that can appear on the graph of some data. The Matlab program has a bunch of data that's already delimited with some number of markers, and will ask the user to choose two of these markers as a start and stop point, and then continue from there.
My question is whether or not Matlab has a built-in function or object that will place some kind of interactive marker on the plot (preferably on the bottom of the graph so that it doesn't obscure the data) that the user can click on so that I can get a call-back function from it and see which marker the user chose (and also perhaps have the ability to change its color and such to represent its selection).
Preferably the answer will not involve any add-ons, but any answer and any help would be greatly appreciated. Thank you!
Here is a very simple example using ginput, which asks the user to select a starting and ending points from which to plot the data.
clear
clc
close all
x = 1:15*pi;
figure
plot(x,sin(x),'LineWidth',2);
uiwait(msgbox('Select a start and finish point'))
a = zeros(1,2);
[a,~] = ginput(2);
xStart = a(1);
xFinish = a(2);
set(gca,'XLim',[xStart xFinish],'XTick',round(xStart):1:round(xFinish))
Is it something like this you had in mind? Do you really need a callback or is this sufficient? If not could you elaborate on what kind of markers you would need?
Hope that helps!

VL_SLIC MATLAB Output for VL_FEAT

I am using the VL_SLIC function in MATLAB and I am following the tutorial for the function here: http://www.vlfeat.org/overview/slic.html
This is the code I have written so far:
im = imread('slic_image.jpg');
regionSize = 10 ;
regularizer = 10;
vl_setup;
segments = vl_slic(single(im), regionSize, regularizer);
imshow(segments);
I just get a black image and I am not able to see the segmented image with the superpixels. Is there a way that I can view the result as shown in the webpage?
The reason why is because segments is actually a map that tells you which regions of your image are superpixels. If a pixel in this map belongs to ID k, this means that this pixel belongs to superpixel k. Also, the map is of type uint32 and so when you try doing imshow(segments); it really doesn't show anything meaningful. For that image that is seen on the website, there are 1023 segments given your selected parameters. As such, the map spans from 0 to 1023. If want to see what the segments look like, you could do imshow(segments,[]);. What this will do is that the region with the ID of 1023 will get mapped to white, while the pixels that don't belong to any superpixel region (ID of 0), gets mapped to black. You would actually get something like this:
Not very meaningful! Now, to get what you see on the webpage, you're going to have to do a bit more work. From what I know, VLFeat doesn't have built-in functionality that shows you the results like what is seen on their webpage. As such, you will have to write code to do it yourself. You can do this by following these steps:
Create a map that is true that is the same size as the image
For each superpixel region k:
Create another map that marks true for any pixel belonging to the region k, and false otherwise.
Find the perimeter of this region.
Set these perimeter pixels to false in the map created in Step #1
Repeat Step #2 until we have finished going through all of the regions.
Use this map to mask out all of the pixels in the original image to get what you see in the website.
Let's go through that code now. Below is the setup that you have established:
vl_setup;
im = imread('slic_image.jpg');
regionSize = 10 ;
regularizer = 10 ;
segments = vl_slic(single(im), regionSize, regularizer);
Now let's go through that algorithm that I just mentioned:
perim = true(size(im,1), size(im,2));
for k = 1 : max(segments(:))
regionK = segments == k;
perimK = bwperim(regionK, 8);
perim(perimK) = false;
end
perim = uint8(cat(3,perim,perim,perim));
finalImage = im .* perim;
imshow(finalImage);
We thus get:
Bear in mind that this is not exactly the same as what you get on the website. I simply went to the website and saved that image, then proceeded with the code I just showed you. This is probably because the slic_image.jpg image is not the exact original that was given in their example. There seems to be superpixels in areas where there are some bad quantization artifacts. Also, I'm using a relatively old version of VLFeat - Version 0.9.16. There may have been improvements to the algorithm since then, so I may not be using the most up to date version. In any case, this is something for you that you can start with.
Hope this helps!
I found these lines in vl_demo_slic.m may be useful.
segments = vl_slic(im, regionSize, regularizer, 'verbose') ;
% overaly segmentation
[sx,sy]=vl_grad(double(segments), 'type', 'forward') ;
s = find(sx | sy) ;
imp = im ;
imp([s s+numel(im(:,:,1)) s+2*numel(im(:,:,1))]) = 0 ;
It generates edges from the gradient of the superpixel map (segments).
While I want to take nothing away from ~ rayryeng's ~ beautiful answer.
This could also help.
http://www.vlfeat.org/matlab/demo/vl_demo_slic.html
Available in: toolbox/demo

How to Creat MATLAB GUI for this code?

Hi everyone I wrote this code using MatLab and I need to design a GUI as the following
Draw Button: to draw the path.
Scan Button: If I want to take an image using "Image Acquisition"
Static Text : to show the angels,number of objects and the centers (Individual)
Axes : To show the image after the processing
And is there any reference I should read to help me??
The Code:
im1=imread('C:\Users\Shadow Of Dark\Desktop\sample','jpeg');
im1=rgb2gray(im1);
level=graythresh(im1)
bwfram3=im2bw(im1,level);
bw2=bwareaopen(bwfram3,20);
se=strel('disk',10);
bw2=imclose(bw2,se);
bw2=imcomplement(bw2);
[labeled,numObjects] = bwlabel(bw2,4);
imshow(labeled);
numObjects
info=regionprops(labeled,'all');
centers=cat(2,info.Centroid)
hold on;
angles=zeros(1,numObjects);
j=0;
for i=1:2:2*numObjects-2
l = line([centers(i) centers(i+2)],[centers(i+1) centers(i+3)]);
set(l,'linewidth',3,'color','r');
angles(1,i-j)= atan((centers(i+1) - centers(i+3))/(centers(i) - centers(i+2)))*180/pi;
j=j+1;
end
angles
Firstly, draw in a paper (or Enterprise Architect, ...) what you want and where in the layout. Afterwards, think of the sequence diagram of your process and write it in a paper. Later, divide your code into some functions, related to the steps you have described. Then, create a GUI with the GUI Editor in MATLAB and add a graphical element to your layout. Finally, link each function you have described to your graphical element (read the official help to do it).
(Alternatively, you can do it quicker mixing all these steps, but it is not an appropriate way of doing it).
I find this list to be quite usefull for getting started:
http://www.mathworks.com/matlabcentral/fileexchange/24861-41-complete-gui-examples
You may also want to look at the examples that are already included in matlab.
Go to Start > Matlab > GUIDE