Friday, December 4, 2020
Add arrays to a structure
Num2cell is a useful function. The important part is that it could convert an array (m x n) to scalar array (y x 1) so you could add this to a structure.
aa=table2struct(readtable((fullfile(filePath0,'curve','params',file0(1).name))));
%This is the structure you want to add new values to
file1=dir(fullfile(filePath0,'ROI_dark*.mat'));
dark_files=load(fullfile(filePath0,file1(1).name),'Intensity','dff0');
%Then you got two variables, both are two dimensional array. To add them, you have to first convert them into cell:
cc=num2cell(dark_files.Intensity,1);
%Then add them:
[aa.dark_Intensity]=cc{:};
Friday, November 27, 2020
low cost microscopes
1. smart design
https://www.osapublishing.org/DirectPDFAccess/73B7846B-A422-B22A-AA38B1E6131DE5F9_429869/boe-11-5-2447.pdf?da=1&id=429869&seq=0&mobile=no
2. not fancy
https://www.instructables.com/ARPM-Another-raspberry-pi-microscope-made-from-Ple/
control of motion (for adujustment of focus):
https://www.robotshop.com/community/forum/t/retracting-linear-actuator-with-raspberry-pi/43024/6
Since you want to control the speed and the position of the actuator, I would recommend using a linear actuator including a potentiometer like this one: https://www.robotshop.com/en/l16-linear-actuator-351-50mm-12v-w--potentiometer-feedback.html 89
This will allow you to track the position of the actuator. Note that you will need a microcontroller to read the value of the potentiometer.
To control the speed of the actuator I would recommend any regular DC motor driver depending on the specifications of the actuator.
Friday, October 23, 2020
Earphone (Windows sonic for headphones) is back again!
For a while, my Dell laptop does not recognize any earphones after some update of windows. I tried to fixed but failed till today. Here is the link to how to:
https://answers.microsoft.com/en-us/windows/forum/all/windows-10-spatial-sound-options-greyed-out/4a3045fc-92ce-4f7a-a9ba-9adc79c3dd8d
It seems the driver was not correct, but when you updated it, there is a trick. See below the complete solution.
Hi,
Thank you for writing to Microsoft Community Forums.
I appreciate you for providing the details and the screenshot to help us in understanding this issue, we will look into this for you. However, in order to get clarity and to find the root cause of the issue, please reply with the answers to the questions below.
What is the make and model of your system?
Was there any major change or an update on your system prior to which you weren’t facing this issue?
Meanwhile, this issue could occur if Mono Audio is enabled within the Windows Settings. Hence, I would suggest you to toggle Off the Turn on mono audio if it is set to On, by going to Settings > Ease of Access > Audio and check if it helps.
I would also recommend you to click on the Enhancements tab under Speakers / Headphones Properties and check if all the enhancements are turned Off. If the issue persists, I would suggest you to install the default Windows audio device driver and check if you are able to enable the Spatial Sound. To do that please follow the steps below.
Steps to install High Definition Audio Device driver:
Press the Windows key and R key, this will open the Run dialogue box for you.
Type devmgmt.msc and press Enter, this will open the Device Manager.
Expand Sound, video and game controllers, right-click on the driver that is installed and select Update driver.
Select Browse my computer for driver software. In the upcoming window, click on Let me pick from a list of available drivers on my computer. This will open a window for you to select a device driver that you want to install for your hardware.
Select High Definition Audio Device and click on Next. Follow the onscreen procedure to complete the installation.
Restart the system and check if you are able to enable the Spatial Sound feature.
If the issue still persists, please get back to us with the results of the troubleshooting steps suggested above along with the screenshot of the Device Manager window, keeping ‘Sound, video and game controllers’ expanded.
Note: When including the screenshot in your response, kindly make sure that there are no personally identifiable information within the screenshot.
We await your response.
Aaron Summith
Microsoft Community – Moderator
Friday, October 9, 2020
Sunday, September 6, 2020
how to make gradient dots in illustrator
https://shirtoid.com/tutorials/halftone-gradient-in-illustrator/
Saturday, August 22, 2020
how to make a list of stringes for box plot
str1='G7f';
str2='XCaMP';
group=[repmat({str1},3,1);repmat({str2},3,1)];
result is:
'G7f'
'G7f'
'G7f'
'XCaMP'
'XCaMP'
'XCaMP'
However, if you use
group=[repmat(str1,3,1),repmat(str2,3,1)];
the result will be
'G7fXCaMP'
'G7fXCaMP'
'G7fXCaMP'
Tuesday, August 11, 2020
Commands to summon matlab from cluster commuting
From the terminal of the linus type:
bsub -XF -n1 matlab -desktop
Thursday, July 30, 2020
Use of complex number to resolve a practical problem
In analyzing the tuning response of visual cortex neurons, there is a need to find the preferred direction and the opposition as well as orthognal directions. This is not an easy task, but could be conveniently achieved by using complex numbers. When you find the preferred direction through gaussian fitting, you could create a complex vector y1Tmp=exp(1i*(y1-1)*2*pi/angleNO). Then find the opposition direction:y2=angle(y1Tmp*exp(1i*pi)). The orthognal direction is y3=angle(y1Tmp*exp(1i*pi/2)). And the other orthognal direction is y4=angle(y1Tmp*exp(-1i*pi/2)). This way we could easily calculate the Orientation Selectivity of neurons.
Wednesday, July 29, 2020
The best article for the introduction of General Linear Model
http://psych.colorado.edu/~carey/qmin/qminChapters/QMIN09-GLMIntro.
The General Linear Model (GLM): A gentle introduction
Wednesday, May 20, 2020
How to make a movie from your screen and then edit frames in ImageJ
Task: I want to make a movie of the 3D flyby of the microscope model, but since the control of rotation is not perfect, need to edit the frames
Step1: Record movie. use VLC media player, choose Media>Open Capture device> capture Device>Capture Mode: choose "Desktop"; then change "play" to "convert". Now another window pops out: choose the file format you want to same and where you want to save. Then click "start". You are now recording your screen. I saved into MP4.
Step2: Install FFMEG. MP4 cannot be imported by Imagej. Even if you convert it into avi by VLC media player, it is still cannot be imported by imagej. So I need to convert it to avi. This could be best achieved by FFMEG, which is an open-source video converting software. Download it from its website and install it. Here is how:https://www.youtube.com/watch?v=qjtmgCb8NcE
Step3: With FFMEG, I first tried this command (ffmpeg -i mimsflyby2.mp4 mimsflyb2.avi), but get an error when I tried to open the avi file with imagej "("/An error occured reading the AVI file. Unsupported compresion: 34504d46 'FMP4".). Then I found another command from here http://imagej.1557.x6.nabble.com/Importing-avi-td5000582.html, and it worked: ffmpeg -i myInputFile.avi -pix_fmt nv12 -f avi -vcodec rawvideo convertedFile.avi
Now we could edit frames in ImageJ!
Sunday, May 17, 2020
Thursday, April 16, 2020
How to display both percentage and value in a piechart in matlab
https://www.mathworks.com/matlabcentral/answers/518138-how-to-show-both-value-and-percentage-in-a-piechart
Thanks to Ameer Hamza, we have the answer now:
X = [1/3 2/3];
value = compose(['Val=%.3f'], X);
percents = compose([newline 'P=%.3f%%'], X/sum(X)*100);
pie(X, strcat(value, percents))
Wednesday, April 15, 2020
find vs logical indexing
people usually use "find" to get some values with a threshold, but the logically indexing is much easier and faster. This is the lesson I learned today:
https://www.mathworks.com/help/matlab/matlab_prog/find-array-elements-that-meet-a-condition.html
https://www.mathworks.com/matlabcentral/answers/66992-logical-indexing-is-usually-faster-than-find
n = 1e6;
r = rand(n,1);
f = randn(n,1)+10;
si = r>0.5;
tic
j = find(si);
s1 = f(j); % with FIND
toc
tic
s2 = f(si); % with logical indexing
toc
all(s1==s2)
This is the best example I found, I usually used s1 method, but s2 is faster, if you dont' need the actual index number
Sunday, April 12, 2020
load and wirte tif stacks in matlab
It takes time to search for these codes, for convenience, let me keep a copy her for everyone.
This will read from a tif stack (not many single files):
Read part:
fname = '20191229_fov02_14.tif';
info = imfinfo(fname);
num_images = numel(info);
B = imread(fname,1);
for k = 2:num_images
A = imread(fname, k);
B = cat(3,B,A);
end
Save part:
outputFileName = 'filteredbinary.tif';
imwrite(afterOp(:, :, 1), outputFileName, 'Compression','none');
for K=2:length(afterOp(1, 1, :))
imwrite(afterOp(:, :, K), outputFileName, 'WriteMode', 'append', 'Compression','none');
end
dilution, errosion, openning and closing
These are important basic concepts in image processing. see nice videoes here:
https://www.youtube.com/watch?v=ZTbGlriKFtU
https://www.youtube.com/watch?v=IcBzsP-fvPo
learning matlab image processing-1: imbinarize
Today I found a great function of matlab for image processing: imbinarize
This function actually replaces the im2bw function. To get an idea of the difference, here is an example.
If we just the old code and the new function in 'global'(default) model. There is not much difference:
level = 0.57;
Ithresh = im2bw(Igray,level);
BW=imbinarize(Igray);
imshowpair(Ithresh, BW, 'montage');
title('old (left) vs new (right,global mode)')
However, the really useful part is the 'adaptive' function for this binarizer:
level = 0.57;
Ithresh = im2bw(Igray,level);
BW=imbinarize(Igray,'adaptive');
imshowpair(Ithresh, BW, 'montage');
title('old (left) vs new (right,global mode)')
This actually saves the effort to split the channels of RGB and segment them separately, as described here in the old version of matlab (https://www.youtube.com/watch?v=1-jURfDzP1s, a very nice presentation).
Find out more details about this function in https://www.mathworks.com/help/images/ref/imbinarize.html
Good thing is that it also works for 3D stacks. will give it try:)
Subscribe to:
Posts (Atom)