How to resave images existing on disc in DM 3.4 (Force a replacement.) - save

Try to do some image edit (add text and scale bar) and then automatically save/replace the original image, the codes work well with DM 2.0 and previous verison, but it does not work with 3.4 and 3.0, it shows " the process can not access the file because it is being used by another process". Is there any other way to do this with 3.4 and 3.0? thx
image front:=getfrontimage()
string imgname=getname(front)
string handler = "Gatan 3 Format"
ImageDocument doc = GetFrontImageDocument()
string thispath=pathconcatenate(currentdirectory, imgname)
doc.ImageDocumentSaveToFile( handler, thispath)

You can not save a file to a file-name of a currently opened file. Instead, you want to "re-save" your opened file. The easiest way to do that would be
image img := GetFrontImage()
img *= -1 // Just something to modify the image
img.Save()
If you want to do the same with an ImageDocument instead, it would be
imageDocument doc = GetFrontImageDocument()
doc.ImageDocumentSave(1)
The parameter in the command can either be:
0 = Always save, never prompt (Use linked location or folder of DigitalMicrograph.exe if not linked.)
1 = Save without prompting, if already linked to file, else prompt
2 = Always prompt
The following commands can also be useful when working with files and imageDocuments:
image img := GetFrontImage()
imageDocument doc = img.ImageGetOrCreateImageDocument()
Result( "\n Image ["+img.ImageGetLabel()+"] " )
if ( doc.ImageDocumentIsLinkedToFile() )
Result( "currenlty linked to:" + doc.ImageDocumentGetCurrentFile() )
else
Result( "not linked to a file." )

Related

What does the command String imageName( "../data/HappyFish.jpg" ); do?

I am a total beginner in OpenCV. I was learning a program to load and display an image where the below statement is used.
String imageName( "../data/HappyFish.jpg" ); //by default
what does this statement do?
This statement is the folder directory of the image file HappyFish.jpg in the OpenCV example Load and Display an Image. Simply it is used with imread to indicate the location where our image file is located.
image = imread( imageName, IMREAD_COLOR ); // Read the file

Batch save all opened files in GIMP .xcf

I have a series of manually edited images and layers in GIMP, each set is in a single tab. All want to save all of them into different .xcf's.
I am aware of some scripts to export them as images (like this one), but I want to save them as .xcf, not export the images. Moreover, I would like to have them in a single folder, so that I can load them all in the future.
Is there any script to do this?
You can save all projects using this code bellow
dirname = “Path of file”
path = “File name”
imgs = gimp.image_list();
num = 0;
for img in imgs:
for layer in img.layers:
fullpath = os.path.join(path, dirname+str(num)+'.xcf');
pdb.gimp_xcf_save(0, img, layer, fullpath, fullpath);
num += 1;
Or, if you can install complete plugin in https://github.com/Tushn/GIMP-Plugins/blob/master/src/saveproject.py
Instructions for install in https://github.com/Tushn/GIMP-Plugins
If you want open all file, so it’s enough that you mark all xcf in directory and enter in GIMP (click right buttom mouse, case your GIMP is not default file).

python 3.5 no print output to screen

Using Python 3.5 I have created code to process a file and write output to another file. Following is relevant code;
with open('2016_01_22_Investor_Companies_stops.txt','r') as stops_Investor_Companies:
stops_Investor_Companies = stops_Investor_Companies.read()
stops_Investor_Companies = nltk.word_tokenize(stops_Investor_Companies)
stops_Investor_Companies= [w.lower() for w in stops_Investor_Companies]
stops_Investor_Companies = str(stops_Investor_Companies)
outfile = open ('stops_Investor_Companies_cln.txt', 'w')
outfile.write(stops_Investor_Companies)
print ('1. Investor Companies')
print (' ')
with open('stops_Investor_Companies_cln.txt','r') as fin:
print(fin.read())
print (' ')
The result is that the text 1. Investor Companies prints to the screen but the file stops_Investor_Companies_cln.txt is not printed to the screen.
However, I can print the file stops_Investor_Companies_cln.txt to the screen using same code snippet as a separate script;
with open('stops_Investor_Companies_cln.txt','r') as fin:
print(fin.read())
You are not closing the file before opening it again. Data is flushed in file only after you close it.
Try closing the file before opening it again:-
outfile = open ('stops_Investor_Companies_cln.txt', 'w')
outfile.write(stops_Investor_Companies)
outfile.close()
Or you can use one more with option to open the file so that closing of file is taken care of...
Since you haven't closed the file before opening it again, you're not seeing the new data. What you should do is use another with statement when you open the file for writing so it gets closed properly.

Calculating surface and storing as Excel file

I'm new to imageJ and I am trying to analyze several images:
I have a code that can analyze color threshold for a set of images in a directory and store them separately:
input = "/m_3/ImageJ/test_folder/";
output = "/m_3/ImageJ/finished2/";
function action(input, output, filename) {
open(input + filename);
run("Set Scale...", "distance=872 known=9 pixel=1 unit=cm");
run("Color Threshold...");
// Color Thresholder 1.48v
// Autogenerated macro, single images only!
.
.
.
// Colour Thresholding-------------
saveAs("Jpeg", output + filename);
close();
}
setBatchMode(true);
list = getFileList(input);
for (i = 0; i < list.length; i++)
action(input, output, list[i]);
setBatchMode(false);
Now I want to calculate the area of the newly saved images and this should work with the function measure..
run("Measure");
How can I store the calculations in .xls or .csv -files?
Is it also possible to calculate the area of all the files in one directory and store the results in just one .xls or .csv -file?
Have a look at the explanation how to apply a common operation to a complete directory on the Fiji wiki. You can open each of the newly save images, set a threshold, measure, and close each image as follows:
open("/path/to/your/image.jpg");
setAutoThreshold("Default");
run("Measure");
close();
and paste that code into the Process Folder template (Templates > IJ1 Macro > Process Folder) of the script editor.
The results table can afterwards be saved as an .xls file via File > Save As... or:
saveAs("Results", "/path/to/your/file.xls");

Multiple input file tags with IOS 6+ on iPad/iPhone

EDIT :
I've been able to resolve this, after finding that iOS uploads every image as "image.jpg". In freeASPUpload.asp, I changed the following :
For Each fileItem In UploadedFiles.Items
filePath = path & fileItem.FileName
Set streamFile = Server.CreateObject("ADODB.Stream")
streamFile.Type = adTypeBinary
streamFile.Open
StreamRequest.Position=fileItem.Start
StreamRequest.CopyTo streamFile, fileItem.Length
streamFile.SaveToFile path & FileName, adSaveCreateOverWrite
streamFile.close
Set streamFile = Nothing
fileItem.Path = filePath
Next
To :
For Each fileItem In UploadedFiles.Items
FileName = GetFileName(path, fileItem.FileName)
fileItem.FileName = FileName
filePath = path & fileItem.FileName
Set streamFile = Server.CreateObject("ADODB.Stream")
streamFile.Type = adTypeBinary
streamFile.Open
StreamRequest.Position=fileItem.Start
StreamRequest.CopyTo streamFile, fileItem.Length
streamFile.SaveToFile path & FileName, adSaveCreateOverWrite
streamFile.close
Set streamFile = Nothing
fileItem.Path = filePath
Next
This is within the save function of the script. The GetFileName function iterates over what is in the folder already, and adds a number until it is unique. It then updates the file key to its new name. I've left an "image.jpg" file in the temp folder, so that it always finds one. That works for now.
What I've found, however, is for some reason, it flips the second photo out of the five that the form allows for..
I will try to fix that / look for others with the same issue. I've always had problems with iPhones and iPads rotating pictures, and it's never consistent.
I'm trying to grab multiple files from a mobile fleet of iPads and iPhones. Currently I have 5
<input type="file" name="fileX" accept="image/*">
This works fine in a browser (using free asp upload / classic ASP). In testing, it works with IOS, but only if I send one file. If I send more then one via the form, I get the error 'file not found'. It seems like the files aren't being sent at all.
The file not found kicks back when trying to manipulate the file via FSO.
Uploads here :
Dim Upload, fileName, fileSize, ks, i, fileKey
Set Upload = New FreeASPUpload
SaveFiles = ""
uploadsDirVar = "directory"
Upload.Save(uploadsDirVar)
ks = Upload.UploadedFiles.keys
Errors out here :
Set f=fs.GetFile(uploadsDirVar & "\" & Upload.UploadedFiles(fileKey).FileName)
Any ideas on how I can get around this? Everything I've read points towards the HTML5 multiple tag on a single input. However, in my scenario, this won't work. I'm also tying descriptions for the images to the fields based on field name, restricting the upload to 5, re-sizing the images on the action page before passing it to its final destination and attaching them to an email.
Any advice welcome, and thank you for your time!
**Edit
The issue seems to be that IOS names all uploads "image", coming from either the camera or the library. Now the problem is how to rename the image before the script attempts to upload it. From what I'm understanding, it needs to happen within the asp upload component before it places the file.
See the above edit for the answer. As for the flipped images - turns out they are flipped straight from the iPad. I checked the exif data and I'm not sure how to account for this in my system. If I find the answer, I'll post here.

Resources