How can I save this .tiff file correctly?

3 次查看(过去 30 天)
The code below is the code I wrote to control our microscope and led lights using serial commands.
I am running into a problem with saving it however, the image collected is not being saved correctly. HELP!
The area with the double stars (bold) is where I wrote the code to save our image, and take user input to save the image.
best
Merrilee
%first set up channel....
obj = instrfind('Port', 'COM3')
if isempty(obj)
obj = serial('COM3');
else
fclose(obj);
obj = obj(1)
end
fopen(obj);
set(obj, 'BaudRate', 115200);
set(obj, 'DataTerminalReady', 'off');
set(obj, 'FlowControl', 'hardware');
set(obj, 'Terminator', {10,10});
fprintf(obj, 'M 0');
data = query(obj, 'L? 0');
% this will set current for channel 1
% and the "L" is the limit.
fprintf(obj, 'L 0 700');
currentlimit = query(obj, 'L? 0');
% this will set current for channel 2
fprintf(obj, 'L 1 700');
currentlimit = query(obj, 'L? 1');
% to set or change "brightness Mode" also must turn off LED first before
% changing brightness if doing this in a command line.
fprintf(obj, 'BP 0 100');
brightnessvalue = query(obj, 'BP? 0');
% this will change brightness for channel 2
fprintf(obj, 'BP 0 100');
brightnessvalue = query(obj, 'BP? 0');
% this is the quickest on/off switch(470)
fprintf(obj, 'O 0 1'); %on
fprintf(obj, 'O 0 0'); %off
% and this turns on and off channel 2(560)!!!
fprintf(obj, 'O 1 1') % on
fprintf(obj, 'O 1 0') % off
% now set up imaging....
%vid = videoinput('hamamatsu', 1, 'MONO16_BIN2x2_1024x1024_FastMode');
vid = videoinput('hamamatsu', 1, 'MONO16_BIN4x4_512x512_FastMode');
src = getselectedsource(vid);
%vid.FramesPerTrigger = 10;
% TriggerRepeat is zero based and is always one
% less than the number of triggers.
%vid.TriggerRepeat = 2;
src.ExposureTime = .7;
%when I want to take multiple images, wait awhile and then takee more
%images in the same file.
for i = 1:2
vid.FramesPerTrigger = 10;
fprintf(obj, 'O 0 1'); %on
preview(vid);
%fprintf(obj, 'O 0 1'); %on
start(vid),wait(vid);
for l = 1:2
fprintf(obj, 'O 0 0'); %off
pause (10);
end;
end;
stoppreview(vid);
% below is where my code isn't saving the image correctly - the .tiff file that saves has no data (i think) saved to %it. it just looks like a pixel landscape.
alpha=input('What do you want to name you file? ','s')
lambda = input('Variable ?', 's')
x = getdata(vid);
filename = alpha
RE = lambda
save([filename '.tif'], 'RE');
clear lambda;
closepreview(vid);
delete(vid);
clear vid;

回答(1 个)

Walter Roberson
Walter Roberson 2018-3-20
Use imwrite() or the tiff class to save tif files. save() is for saving as .mat files.
  3 个评论
Merrilee Thomas
Merrilee Thomas 2018-3-20
ok. I rewrote the code to imwrite(x, [filename '.tif']); however, now I get an error that says 4-D data not supported for TIFF files. what do i need to change. I need the images I am taking to be in a tiff format. best, Merr
Walter Roberson
Walter Roberson 2018-3-20
There are a lot of examples in the imwrite documentation. Just pass in RE and then the file name.

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by