I want to make a copy of front image which contains several slice, like this:
image with several slices
I used imageclone function
image front, img
front.getfrontimage()
img=imageclone(front)
img.showimage()
But it only copy the first slices.
Have anyone know how to make a copy of this kind of image >"<
Thanks a lot~
The easiest way to duplicate the image (regardless how it is displayed) is via its "container" - ImageDocument. Here are the codes:
ImageDocument imgDoc = GetFrontImageDocument();
number DoDeepCopy = 1;
ImageDocument newDoc = imgDoc.ImageDocumentClone(DoDeepCopy);
newDoc.ImageDocumentShow();
If you need to manipulate individual slices then it is more complicated. Hope this helps.
In extension to the accepted (correct and best) answer, it's worthwhile knowing how to come from an "image" to its imageDocument. You do this like in this example:
ClearResults()
image frontImg := GetFrontImage()
imageDocument frontDoc = GetFrontImageDocument()
Result( "Grapped from application:" )
Result( "\n\t Image: " + frontImg.ImageGetLabel() + "\t ID = " + frontImg.ImageGetID() )
Result( "\n\t Doc : " + frontDoc.ImageDocumentGetName() + "\t ID = " + frontDoc.ImageDocumentGetID() )
imageDocument docFromImg = frontImg.ImageGetOrCreateImageDocument()
Result( "\n Taken from image:" )
Result( "\n\t Doc : " + frontDoc.ImageDocumentGetName() + "\t ID = " + docFromImg.ImageDocumentGetID() )
image imgFromDoc := frontDoc.ImageDocumentGetImage( 0 )
Result( "\n Taken from imageDocument:" )
Result( "\n\t Image: " + frontImg.ImageGetLabel() + "\t ID = " + imgFromDoc.ImageGetID() )
Note that an image does not necessarily have an imageDocument. The imageDocument is only created when the image is displayed or saved. That is why the command is called ...GetOrCreate.
Similarly, an imageDocument may contain multiple images (or none).
This is all a bit convoluted, and it appears confusing because many of the "correct" commands following the internal class hierarchy are wrapped by simplification commands for scripting convenience.
f.e. Saving an image using SaveSave() takes an image variable, but it really needs to save an imageDocument. So it implicitly gets/creates one. Otherwise, the user would need to script the correct, but more 'complicated' script.Instead of:
string path = "C:\\test.dm4"
image img := GetFrontImage()
img.SaveImage( path )
One would need:
string path = "C:\\test.dm4"
string handler = "Gatan Format"
image img := GetFrontImage()
imageDocument doc = img.ImageGetOrCreateImageDocument()
doc.ImageDocumentSaveToFile( handler, path )
Also note: While the route of using imageDocuments is the correct way, you should know that "linePlot displays" are really special. They are imageDisplay objects that may contain more than one image, whereas imageDocuments are objects which may contain more than one imageDisplay. I am pointing this out so that you know that you need to add new images to an imageDisplay to get more slices in an slice image. If you add them to an imageDocument, you will get multiple linePlot displays in a single file.
Depending on how "deep" you need to know all of this, I would recommend reading the documentation section on "image/imageDocument/imageDisplay/components" and testing things a bit. If questions remain, post them here on StackOverflow :c)
Related
Hello dear programmers,
I have a sequence of images and I would like to perform dilation on each of them with different dilation parameters. Then, I would like to save the processed images with new name including both the old name and the corresponding dilation parameter. My codes are as follows.
Input_folder =
Output_folder =
D = dir([Input_folder '*.jpg']);
Inputs = {D.name}';
Outputs = Inputs; % preallocate
%print(length(Inputs));
for k = 1:length(Inputs)
X = imread([Input_folder Inputs{k}]);
dotLocations = find(Inputs{k} == '.');
name_img = Inputs{k}(1:dotLocations(1)-1);
image1=im2bw(X);
vec = [3;6;10];
vec_l = length(vec);
for i = 1:vec_l
%se = strel('disk',2);
fprintf(num2str(vec(i)));
se = strel('diamond',vec(i)); %imdilate
im = imdilate(image1,se);
image2 = im - image1;
Outputs{k} = regexprep(Outputs{k}, name_img, strcat(name_img,'_', num2str(vec(i))));
imwrite(image2, [Output_folder Outputs{k}])
end
end
As it can be seen, I would like to apply dilation with parameters 3,6 and 10. Let us assume that an image has as name "image1", after processing it, I would like to have "image1_3", "image1_6" and "image1_10". However, I am getting as results "image1_3", "image1_6_3" and "image1_10_6_3". Please, how can I modify my codes to fix this problem?
This is because you rewrite each item of the Outputs variable three times, each time using the previous value to create a new value. Instead, you should use the values stored in Inputs new names. Another mistake in your code is that the size of Inputs and Outputs are equal, while for every file in the input folder, three files must be stored in the output folder.
I also suggest using fileparts function, instead of string processing, to get different parts of a file path.
vec = [3;6;10];
vec_l = length(vec);
Outputs = cell(size(Inputs, 1)*vec_l, 1); % preallocate
for k = 1:length(Inputs)
[~,name,ext] = fileparts([Input_folder Inputs{k}]);
% load image
for i = 1:vec_l
% modify image
newName = sprintf('%s_%d%s', name, vec(i), ext);
Outputs{(k-1)*vec_l+i} = newName;
imwrite(image2, [Output_folder newName])
end
end
I am writing a program in IDL that requires reading n images (each of m pixels) from a directory, convert them to grayscale, concatenate each image as a single vector, and then form a an m * n matrix from the data.
So far I have managed to read and convert a single image to a grayscale vector, but I can't figure out how to extend this to reading multiple image files.
Can anyone advise on how I could adapt my code in order to do this?
(The image files will all be of the same size, and stored in the same directory with convenient filenames - i.e. testpicture1, testpicture2, etc)
Thanks
pro readimage
image = READ_IMAGE('Z:\My Documents\testpicture.jpg')
redChannel = REFORM(image[0, *, *])
greenChannel = REFORM(image[1, * , *])
blueChannel = REFORM(image[2, *, *])
grayscaleImage = BYTE(0.299*FLOAT(redChannel) + $
0.587*FLOAT(greenChannel) + 0.114*FLOAT(blueChannel))
imageVec = grayscaleImage[*]
end
Use FILE_SEARCH to find the names and number of the images of the given name:
filenames = FILE_SEARCH('Z:\My Documents\testpicture*.jpg', count=nfiles)
You will probably also want to declare an array to hold your results:
imageVec = bytarr(m, nfiles)
Then loop over the files with a FOR loop doing what you are doing already:
for f = 0L, nfiles - 1L do begin
; stuff you are already doing
imageVec[*, f] = grayscaleImage[*]
endfor
I have certain images in a directory and I want to load all those images to do some processing. I tried using the load function.
imagefiles = dir('F:\SIFT_Yantao\demo-data\*.jpg');
nfiles = length(imagefiles); % Number of files found
for i=1:nfiles
currentfilename=imagefiles(i).name;
I2 = imread(currentfilename);
[pathstr, name, ext] = fileparts(currentfilename);
textfilename = [name '.mat'];
fulltxtfilename = [pathstr textfilename];
load(fulltxtfilename);
descr2 = des2;
frames2 = loc2;
do_match(I1, descr1, frames1, I2, descr2, frames2) ;
end
I am getting an error as unable to read xyz.jpg no such file or directory found, where xyz is my first image in that directory.
I also want to load all formats of images from the directory instead of just jpg...how can i do that?
You can easily load multiple images with same type as follows:
function Seq = loadImages(imgPath, imgType)
%imgPath = 'path/to/images/folder/';
%imgType = '*.png'; % change based on image type
images = dir([imgPath imgType]);
N = length(images);
% check images
if( ~exist(imgPath, 'dir') || N<1 )
display('Directory not found or no matching images found.');
end
% preallocate cell
Seq{N,1} = []
for idx = 1:N
Seq{d} = imread([imgPath images(idx).name]);
end
end
I believe you want the imread function, not load. See the documentation.
The full path (inc. directory) is not held in imgfiles.name, just the file name, so it can't find the file because you haven't told it where to look. If you don't want to change directories, use fullfile again when reading the file.
You're also using the wrong function for reading the images - try imread.
Other notes: it's best not to use i for variables, and your loop is overwriting I2 at every step, so you will end up with only one image, not four.
You can use the imageSet object in the Computer Vision System Toolbox. It loads image file names from a given directory, and gives you the ability to read the images sequentially. It also gives you the option to recurse into subdirectories.
Afternoon,
I have an odd algorithm. I would like to populate a string of code dynamically based on some user entry.
I have a multi-dimensional array with data in it and a multi-line input text field.
What I want is for a user to be able to enter some text
example:
00
01 - 02 - 03
comments: 12
my code would identify the numbers an treat everything else as text.
Thus, if my array is data[x][#], the # will correspond to their entry.
I would get
algorithm_string = data[x][0] + "\n" + data[x][1] + " - " + data[x][2] + " - " + data[x][3] + "\n" + "comments: " + data[x][12]
So the algorithm would construct the above, and then I could run through the code.
for(var x:int = 0; x < data.length; x++){
some_object._display_text.text = algorithm_string;
}
Ok so I want to first say that relying on a user to put in the entry exactly the way you want is probably not a good idea. They WILL make mistakes and your code WILL eventually not work as expected. I would recommend using 5 inputs restricted to numeric input, and labeling each field with which number should go in it.
However, you can accomplish what you are trying to do above like this:
var parts:Array = myInput.text.split(" ");
for (var i:int=0; i<parts.length, i++){
if(!isNaN(parseInt(parts[i]))){
// you have a number here.
data[x].push(parts[i]);
} else {
//this was not a number so ignore it
}
}
Again let me state I think you should refactor how you get the numbers, but that code will grab the numbers out and put them in the 0,1,2,3,and 4 indexes of your data[x], but relies on the user perfectly inputting the text every time.
Good luck! (refactor) :)
This question is built off of this previous question 'here' I want to make 256 points on the image that all lead to different pdf documents based on the location of the *. I dont want to have to code in 256 separate filepaths. I have attempted some code below and have not been having any luck so far.
for i = 1:256
text(x(i),y(i),'*', 'ButtonDownFcn',['open(''' file ''');']);
end
function [filePath] = file()
%h = impoint;
%position = getPosition(h);
filePath = strcat('C:\Documents and Settings\Sentinelle\Desktop\LCModel\sl5_knt1\sl5_',x(1),'-',y(i),'.pdf');
end
It seems to me that your code is wrong in several places:
the file() function doesn't know the values of x and y
the file() function doesn't use the current value of i
the file path uses x(1) idependently of the value of i
You probably want
for i = 1:256
text(x(i), y(i), '*', 'ButtonDownFcn', ['open(''' file(x(i),y(i)) ''');']);
end
function [filePath] = file( x, y )
filePath = strcat('C:\Documents and Settings\Sentinelle\Desktop\LCModel\sl5_knt1\sl5_',x,'-',y,'.pdf');
end
Assuming x(i) and y(i) are integers, this should work:
prefix = 'C:\Documents and Settings\Sentinelle\Desktop\LCModel\sl5_knt1\sl5_'
for i = 1:256
filePath = [prefix num2str(x(i)) '-' num2str(y(i)) '.pdf'];
text(x(i),y(i),'*', 'ButtonDownFcn',['open(''' filePath ''');']);
end
If they aren't integers, you need to specify how the floating point number will be converted to a string. You can do that with the second argument of num2str, type:
help num2str
for details and browse from there.