I wrote a macro in Fiji to perform a set of operations on all the images in a particular folder. But I ran into trouble and can't get over one problem. I get an error message that says 'There are no images open' when I run the macro. What does it mean? (The images in input folder are of .tif type)
Here's the macro:
input = "C:"+File.separator+"Winter Quarter slides"+File.separator+"CTIA"+File.separator+"Project"+File.separator+"Original Image data"+File.separator+"Input Images"+File.separator;
output = "C:"+File.separator+"Winter Quarter slides"+File.separator+"CTIA"+File.separator+"Project"+File.separator+"Original Image data"+File.separator+"Output Images"+File.separator;
setBatchMode(true);
list=getFileList(input);
for(i=0; i<list.length; i++)
action(input,output,list[i]);
setBatchMode(false);
function action(input,output,filename) {
open(input+filename);
run("16-bit");
run("Gaussian Blur...", "sigma=3");
setAutoThreshold("Otsu");
//run("Threshold...");
setAutoThreshold("Otsu");
setOption("BlackBackground", false);
run("Convert to Mask");
run("Close");
run("Watershed");
saveAs("Tiff", output+filename);
close();
}
close();
Can someone please help me out with it asap?
Thanks!
Another thing that would cause this error would be non-image files in the input directory. You loop through all the content in the folder and treat it like an image. If there is for example a text file, the result of open(input+filename) will not be an open image.
When several windows are open, the macro commands need definition of which window to work on.
In my micros i use ; selectWindow("imagename"); before the command. This should hopfully solve the problem.
I've not used the macro language but I have seen that error when developing in Java. Some Plugins require that an image is showing.
If the image isn't showing after open(input+filename); then you need to run a show function to display the image.
You do
run("Close");
run("Watershed");
saveAs("Tiff", output+filename);
So you close the image and then try to do things to the image which would produce that error.
Related
i'm using this on push button click in Qt:
QString fileName = QFileDialog::getSaveFileName(this, tr("Save file"),
QString(),
tr("(*.csv));
it take 3-4 second to open the save Form. why? how i can improve speed?
Try to connect this slot to a QPushButton:
void MainWindow::openFD(){
QTime myopentime=QTime::currentTime();
for (int i=0;i<1000000;i++) ;//comment out this line for the real test
QString fileName = QFileDialog::getSaveFileName(this,QString(),QString(myopentime.toString("m.s.zzz")+" "+QTime::currentTime().toString("m.s.zzz"))
,tr("*.csv") );
}
Then try to run it with and without the count part.
You will see, that the count part adds some ms... without it there is not even ms (mili-second) of difference in the time shown in filename place.
So, you have to search somewhere else in your code or give us a better example.
PS:
1) You will need :
#include <QTime>
2) The line that counting is there to show you that my method works (since you will see some difference when uncomment)
Result and Answer: The problem is not on QFileDialog if this test will not give you differences but somewhere else in your code or possibly in the Window manager of your OS.
I am pretty new to batch image processing in imageJ. I have a macro that allows me to process several images in a single directory. The problem is that the macro generates an individual summary window for each processed image, leaving me to manually compile all the output data into a single .csv or .xls. I would prefer that all the summary data be automatically compiled into one file. While I have found several sources showing how to do this, it has not been particularly helpful in my situation.
If you could help, I'd be very grateful.
Here is an abbreviated example of the code:
dir1 = getDirectory("Choose Source Directory ");
dir2 = getDirectory("Choose Destination directory");
list = getFileList(dir1);
setBatchMode(true);
for (i=0; i<list.length; i++){
print (list[i]);
open(dir1+list[i]);
name=File.nameWithoutExtension;
//Prepare the image by removing any scale and making 8-bit
run("Set Scale...", "distance=237.3933 known=1 pixel=1 unit=cm
global");
makeRectangle(4068, 5940, 1572, 1320);
run("Crop");
// Convert the image into RGB channels for proper thresholding
run("RGB Stack");
setSlice(3);
//Threshold
setAutoThreshold("Default");
// Analyze particles
// Provides total area of number of cotyledons in image
run("Analyze Particles...", "size=60-Infinity pixel display include
summarize");
run("Revert");
}
//Save the results
selectWindow("Summary");
saveAs("Results", dir2+"Results.xls");
In my tests (with ImageJ 2.0.0-rc-61/1.51n on macOS 10.12.6), repeatedly executing Analyze Particles with the summarize option checked appends the summary to the existing Summary window, which can then be saved as a single file at the end.
For example, the following macro generates two summary lines and then saves them:
setBatchMode(true);
run("Blobs (25K)");
setAutoThreshold("Default");
run("Analyze Particles...", "size=60-Infinity pixel display include summarize");
run("Boats (356K)");
setAutoThreshold("Default");
run("Analyze Particles...", "size=60-Infinity pixel display include summarize");
selectWindow("Summary");
saveAs("Results", "/Users/curtis/Desktop/Results.xls");
I have a weird problem... I want to create a video with the extension .tif with a lot of frames. My script is running well 2 times over 3 but it crashes randomly sometimes...
I have a loop which has the length of the total of frames in the video and at each turn I add a tif to my multipage tif.
There is my code to create the new video :
% --- Create the new frame
newVid.cData = iL(y0:y0end, x0:x0end);
% --- Create the new video
if nbrFrames == 1
imwrite(newVid.cData,dataOutVid);
else
imwrite(newVid.cData,dataOutVid,'WriteMode','append');
end
Each turn I change the value of "newVid.cData". in fact the new video is a portion of an original video in which I focused on a specific object (a mouse for me). "dataOutVid" is the path where I store the new video and the extension of the path is .tif.
How I obtain the path:
disp('Where do you want to save the new video and under which name ?');
[name, path] = uiputfile({'.tif'}, 'Save Video');
dataOutVid = strcat(path,name);
There is the mistake I can possibly have randomly:
Error using imwrite (line 454)
Unable to open file "D:\Matlab\Traitement Vidéo\test.tif" for writing. You might not have write permission.
Error in mouseExtraction(line 164)
imwrite(newVid.cData,dataOutVid,'WriteMode','append');
Well I don't understand why this error appears randomly (one time at the frame 270, another time at the frame 1250, etc...). How is it possible I suddendly loose the right to overwrite my file...
Edit : I already checked if I didn't have a RAM problem but I only use 20% of it during the execution of the script...
I am using raspberry pi with raspicam to run a project. I have downloaded the raspicam library from http://sourceforge.net/projects/raspicam/files/?
I am trying to run a code for image subtraction but not getting results. Here is my code
raspicam::RaspiCam_Cv Camera;
Camera.set(cv::CAP_PROP_FRAME, CV_8UC1);
if(!Camera.open())
{
std::cerr<<"cannot open camera"<<std::endl;
}
Camera.grab();
Camera.retrieve(frame1);
Camera.grab();
Camera.retrieve(frame2);
Camera.grab();
Camera.retrieve(frame3);
while (True)
{
frame1=frame2;
frame2=frame3;
Camera.grab();
Camera.retrieve(frame3);
absdiff(frame2,frame1,d1);
imshow("result1",d1);
absdiff(frame2,frame3,d2);
imshow("result2",d2);
}
when I run this code I get blank frames of result1 and result2 as output. This is just a part of my code ignore if i have missed something.
Well, inside your loop
frame1=frame2;
...
absdiff(frame2,frame1,d1);
that'll be sort of identically zero...
Also, have you considered the timing here? You're grabbing images very close together in the time-domain, so naturally they'll be mostly identical (bar noise and fast motion) so the difference will be near-zero.
Cheers,
I'm using the perl module Image:Imlib2 to resize photos. Here is the code:
#create thumbnail
my $old = Image::Imlib2->load("$upload_dir/$name");
my $new = $old->create_scaled_image(80, 80);
$new->save("$upload_dir/$thumbnail_name");
This code works fine when I am saving a jpg or png file, but whenever I save a gif, I get an internal server error. Here is the error I get in my apache log file:
Image::Imlib2 save error: Unknown error at /path/to/script/script.pl
Any Ideas?
Thanks!
I don't think Imlib2 supports writing GIF files at all. From a rather old mailing list posting:
I discovered that Imlib2 has absolutely NO support for writing out gif files.
Furthermore, if you look at the source, you'll see a couple files of interest:
imlib2-1.4.5/src/modules/loaders/loader_png.c
imlib2-1.4.5/src/modules/loaders/loader_gif.c
Inside loader_png.c you'll find this:
char
load(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity, char immediate_load)
{
/*...*/
}
char
save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
{
/*...*/
}
and inside loader_gif.c, you'll find:
char
load(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity,
char immediate_load)
{
/* ... */
}
but no save implementation. So it looks like Imlib2 can read GIFs but can't write them and that's where your trouble lies.
I'd recommend that you switch to GraphicsMagick and Graphics::Magick. GraphicsMagick is a fork of ImageMagick that is faster and has fewer bugs, this is what Flickr uses internally so it should be good enough for you. GraphicsMagick unfortunately uses the somewhat strange ImageMagick API but you can hide the ugly details behind a wrapper without too much difficulty.
Alternatively, save all your thumbnails as JPEGs or PNGs.