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:)
Tuesday, April 7, 2009
RNA Extraction with TRIZOL
Wear gloves when handling trizol, work RNase-free!
1. Aspirate medium from cells grown in dishes
2. Wash with 1XPBS
3. In the fume hood, add 1 ml TRIzol per ~1x106 cells, that is when culture flask(25 cm2)reaches confluency; or 4ml of Trizol to cells on plastic of 10cm plate;2.5 ml on 60 mm plate;1 ml on 35mm plate.
4. Pipette up and down for 2-3 min until solution is no longer viscous;
5. Centrifuge for 10 min at 9000 rpm at C( No dissolved protein will be pelleted),and transfer supernatant into fresh tube
6. Add 20% of Chloroform for Trizol ( i.e. 0.2 ml Chloroform for each 1 ml Trizol )
7. Close tubes firmly and vortex vigorously for at least 15 seconds(UP TO 1 min)
8. Let sit at room temperature for 2min 30sec
9. Centrifuge for 15 min at 9000rpm at 4C
10. Transfer upper, aqueous phase to fresh 1.5ml tube(0.5ml/tube), avoid transfer of ANY interface!!
11. Add equal volume isopropanol to the clean supernatant and incubate at RT for 15 min.
12.Centrifuge at 15,000 rpm for 15 minutes to pellet the RNA.
13.Discard the supernatant and resuspend the pellet in 70% ethanol. The RNA can be stored in 70% ethanol at -20°C until use.
14.Prior to use, centrifuge at 15,000 rpm for 15 minutes at 4°C and discard supernatant.
15.Remove the supernatant, and air dry the RNA pellet for 5 min at RT
16.Resuspend the pellet in diethylpyrocarbonate (DEPC) treated water 30ul or RNase-free TE buffer forlabeling.
1. Aspirate medium from cells grown in dishes
2. Wash with 1XPBS
3. In the fume hood, add 1 ml TRIzol per ~1x106 cells, that is when culture flask(25 cm2)reaches confluency; or 4ml of Trizol to cells on plastic of 10cm plate;2.5 ml on 60 mm plate;1 ml on 35mm plate.
4. Pipette up and down for 2-3 min until solution is no longer viscous;
5. Centrifuge for 10 min at 9000 rpm at C( No dissolved protein will be pelleted),and transfer supernatant into fresh tube
6. Add 20% of Chloroform for Trizol ( i.e. 0.2 ml Chloroform for each 1 ml Trizol )
7. Close tubes firmly and vortex vigorously for at least 15 seconds(UP TO 1 min)
8. Let sit at room temperature for 2min 30sec
9. Centrifuge for 15 min at 9000rpm at 4C
10. Transfer upper, aqueous phase to fresh 1.5ml tube(0.5ml/tube), avoid transfer of ANY interface!!
11. Add equal volume isopropanol to the clean supernatant and incubate at RT for 15 min.
12.Centrifuge at 15,000 rpm for 15 minutes to pellet the RNA.
13.Discard the supernatant and resuspend the pellet in 70% ethanol. The RNA can be stored in 70% ethanol at -20°C until use.
14.Prior to use, centrifuge at 15,000 rpm for 15 minutes at 4°C and discard supernatant.
15.Remove the supernatant, and air dry the RNA pellet for 5 min at RT
16.Resuspend the pellet in diethylpyrocarbonate (DEPC) treated water 30ul or RNase-free TE buffer forlabeling.
Subscribe to:
Posts (Atom)
