I have a .csv file and I need to read it using vtk and display in vtk window itself.How Is it possible?
EDIT
Here is my code
vtkSmartPointer<vtkDelimitedTextReader> reader =
vtkSmartPointer<vtkDelimitedTextReader>::New();
reader->SetFileName("sample.csv");
reader->DetectNumericColumnsOn();
reader->GlobalWarningDisplayOff();
reader->SetFieldDelimiterCharacters(",");
reader->Update();
vtkSmartPointer<vtkTableToPolyData> tabletodata = vtkSmartPointer<vtkTableToPolyData> ::New();
tabletodata->SetInputConnection(reader->GetOutputPort());
tabletodata->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputData(tabletodata->GetOutput());
Here is my csv file opened in notepad.It has 256 rows and columns
anyone help please
To read a csv, use the vtkDelimitedTextReader.
It ouptuts a vtkTable. You can not display it in a render view but you can convert it into a vtkPolyData with the vtkTableToPolyData filter. https://vtk.org/doc/nightly/html/classvtkTableToPolyData.html
edit : you have to tell this filter wich CSV column is X, Y and Z
Then a vtkPolyData can be rendered in a 3d view. Example of polydata rendering: https://lorensen.github.io/VTKExamples/site/Cxx/Rendering/Cone3/
Related
I'm trying to write a code in Image J that will:
Open all images in separate windows that contains "488" within a folder
Use look up tables to convert images to green and RGB color From ImageJ, the commands are: run("Green"); and run("RGB Color");
Adjust the brightness and contrast with defined values for Min and Max (same values for each image).
I know that the code for that is:
//run("Brightness/Contrast..."); setMinAndMax(value min, value max); run("Apply LUT");
Save each image in the same, original folder , in Tiff and with the same name but finishing with "processed".
I have no experience with Java and am very bad with coding. I tried to piece something together using code I found on stackoverflow and on the ImageJ website, but kept getting error codes. Any help is much appreciated!
I don't know if you still need it, but here is an example.
output_dir = "C:/Users/test/"
input_dir = "C:/Users/test/"
list = getFileList(input_dir);
listlength = list.length;
setBatchMode(true);
for (z = 0; z < listlength; z++){
if(endsWith(list[z], 'tif')==true ){
if(list[z].contains("488")){
title = list[z];
end = lengthOf(title)-4;
out_path = output_dir + substring(title,0,end) + "_processed.tif";
open(input_dir + title);
//add all the functions you want
run("Brightness/Contrast...");
setMinAndMax(1, 15);
run("Apply LUT");
saveAs("tif", "" + out_path + "");
close();
};
run("Close All");
}
}
setBatchMode(false);
I think it contains all the things you need. It opens all the images (in specific folder) that ends with tif and contains 488. I didn't completely understand what you want to do with each photo, so I just added your functions. But you probably won't have problems with adding more/different since you can get them with macro recorder.
And the code is written to open tif files. If you have tiff just be cerful that you change that and also change -4 to -5.
The spacing on the y axis label get all wrong when printing with print
The code to reproduce the issue is:
data1 = [1:10:100]
data2 = [100:10:200]
file = "plottest.png"
[at ho ht] = plotyy(data1,data1,data2,data2);
ylabel(at(1),"Concentration of O_2 (mol/m^3)");
print(gcf,file);
I'm using the qt graphics tool.
Output to figure window (and also desired result):
What gets printed to PNG file:
One workaround could be using the latex interpreter as
ylabel(at(1),"Concentration of $O_2$ (mol/m^3)", 'Interpreter', 'latex');
I'm brand new to imageJ and its macros, I can't save a Results file from Particle Analyze in a loop.
Here is my code, made of what I just learned on internet and I just can't include [i] in the saveAs function and there is a mismatch with the saving of the images while I have not even try yet to save it...
path1=getDirectory("Mydir");
list=getFileList(path1);
path2=getDirectory("My output dir");
setBatchMode(true);
for(i=0;i<list.length;i++){
open(path1+list[i]);
run("8-bit");
run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 show=[Bare Outlines] display clear");
selectWindow("Results");
saveAs("Results", path2+"Results.xls");
close();
}
setBatchMode(false);
run("Close");
To save the Results window in each cycle of your for loop, you can add the counter variable i to the file name string:
saveAs("Results", path2+"Results" + i + ".xls");
It might be a good idea to also include the original image file name into the results file name, such as:
saveAs("Results", path2+"Results" + list[i] + ".xls");
NB: I had to add to add setAutoThreshold("Default"); before the Analyze Particles... command to make your macro work on sample images like the Blobs example image, because the command need a thresholded/binary image.
I want to generate a barcode.png file but the file generated contains the Barcode number also and I don't want that, I only want image without Text.
How to do that?
Below is my code:-
Barcode barcode3;
barcode3 = BarcodeFactory.createCode128("CODE128x1");
barcode3.setResolution(300);
BarcodeImageHandler.savePNG(barcode3, new File("Code128-1.png"));`
The text will not generate in case you pass the null parameter to setFont function of Barcode class. Your code looks like as below
Barcode barcode3;
barcode3 = BarcodeFactory.createCode128("CODE128x1");
barcode3.setFont(null);
barcode3.setResolution(300);
BarcodeImageHandler.savePNG(barcode3, new File("Code128-1.png"));
only adding this to your code :
barcode3.setDrawingText(false);
the method above will remove text from the barcode. full code
Barcode barcode3;
barcode3 = BarcodeFactory.createCode128("CODE128x1");
barcode3.setDrawingText(false);
barcode3.setResolution(300);
BarcodeImageHandler.savePNG(barcode3, new File("Code128-1.png"));
I have a load of data in 100 .sdf files (labelled 0000.sdf to 0099.sdf), each of which contain a still image, and I'm trying to produce a .gif from these images.
The code I use to plot the figure are (in the same directory as the sdf files):
q = GetDataSDF('0000.sdf');
imagesc(q.data');
I've attempted to write a for loop that would plot the figure and then save it with the same filename as the sdf file but to no avail, using:
for a = 1:100
q=GetDataSDF('0000.sdf');
fh = imagesc(q.dist_fn.x_px.Left.data');
frm = getframe( fh );
% save as png image
saveas(fh, 'current_frame_%02d.jpg');
end
EDIT: I received the following errors when trying to run this code:
Error using hg.image/get
The name 'Units' is not an accessible property for an instance of class 'image'.
Error in getframe>Local_getRectanglesOfInterest (line 138)
if ~strcmpi(get(h, 'Units'), 'Pixels')
Error in getframe (line 56)
[offsetRect, absoluteRect, figPos, figOuterPos] = ...
Error in loop_code (line 4)
frm = getframe( fh );
How do I save these files using a for loop, and how do I then use those files to produce a movie?
The reason for the error is that you pass an image handle to getframe, but this function excpects a figure handle.
Another problem is that you always load the same file, and that you saveas will not work for gifs. (For saving figures as static images, maybe print is the better option?)
I tried to modify my own gif-writing loop so that it works with your data. I'll try to be extra explicit in the comments, since you seem to be starting out. Remember, you can always use help name_of_command to display a short Matlab help.
% Define a variable that holds the frames per second your "movie" should have
gif_fps = 24;
% Define string variable that holds the filename of your movie
video_filename = 'video.gif';
% Create figure 1, store the handle in a variable, you'll need it later
fh = figure(1);
for a = 0:99
% Prepare file name so that you loop over the data
q = GetDataSDF(['00' num2str(a,'%02d') 'sdf']);
% Plot image
imagesc(q.dist_fn.x_px.Left.data');
% Force Matlab to actually do the plot (it sometimes gets lazy in loops)
drawnow;
% Take a "screenshot" of the figure fh
frame = getframe(fh);
% Turn screenshot into image
im = frame2im(frame);
% Turn image into indexed image (the gif format needs this)
[imind,cm] = rgb2ind(im,256);
% If first loop iteration: Create the file, else append to it
if a == 0;
imwrite(imind,cm,video_filename,'gif', 'Loopcount',inf);
else
imwrite(imind,cm,video_filename,'gif','WriteMode','append','DelayTime',1/gif_fps);
end
end
One more note: When the size of the data is the same for each plot, it makes sense to only use the plot(or in this case, imagesc) command once, and in later loop iterations replace it with a set(ah,'Ydata',new_y_data) (or in this case set(ah,'CData',q.dist_fn.x_px.Left.data'), where ah is a handle of the plot axes (not the plot figure!). This is orders of magnitude faster than creating a whole new plot in each loop iteration. The downside is that the scaling (here, the color-scaling) will be the same for each plot. But in every case that I have worked on so far, that was actually desirable.