2013-10-17 56 views
0

我来分析一组图像,而这些都是我需要执行如下操作:图片操纵 - 强度和TIF图像

  1. 总和另一组图像(称为开放光束中的代码) ,计算中位数并旋转90度;
  2. 加载一组图像,列在文件“list.txt”中;
  3. 图像已被收集在一组3组。对于每个组,我想要生成的图像的强度值是图像中位数高于某个阈值的3倍,否则等于强度值的总和;
  4. 对于每组三个图像,减去从所述合成图像(在3计算)

考虑TIFS之一的开放光束中位数(在1计算)使用上述方法生产的,我最大值是65211,这不是3 *相应组的三个图像的中位数(我考虑像素位置检查)。你有什么建议,为什么会发生这种情况,以及我如何解决它?

该代码报告如下。谢谢!

%Here we calculate the average for the open beam 
clear; 
j = 0; 
for i=1:5 
    s = sprintf('/Users/Alberto/Desktop/Midi/17_OB_2.75/midi_%04i.fits',i); 
    j = j+1; 
    A(j,:,:) = uint16(fitsread(s)); 
end 

OB_median = median(A,1); 
OB_median = squeeze(OB_median); 
OB_median_rot=rot90(OB_median); 

%Here we calculate, for each projection, the average value from the three datasets 

%Read list of images from text file 
fid = fopen('/Users/Alberto/Desktop/Midi/list.txt', 'r'); 
a = textscan(fid, '%s'); 
fclose(fid); 

%load images 
j = 0; 
for i = 1:1:42 %556 entries; 543 valid values 
     s = sprintf('/Users/Alberto/Desktop/Midi/%s',a{1,1}{i,1}); 
     j = j+1; 
     A(j,:,:) = uint16(fitsread(s)); 
end 

threshold = 80 %This is a discretional number. I put it after noticing 
%that we get the same number of pixels with a value >100 if we use 80 or 50. 

k = 0; 
for ii = 1:3:42 
    N(1,:,:) = A(ii,:,:); 
    N(2,:,:) = A(ii+1,:,:); 
    N(3,:,:) = A(ii+2,:,:); 
    median_N = median(N,1); 
    median_N = squeeze(median_N); 
    B(:,:) = zeros(2160,2592); 
    for i = 1:1:2160 
     for j = 1:1:2592 
      RMS(i,j) = sqrt((double(N(1,i,j).^2) + double(N(2,i,j).^2) + double(N(3,i,j).^2))/3); 
      if RMS(i,j) > threshold 
       %B(i,j) = 30; 
       B(i,j) = 3*median_N(i,j); 
      else 
       B(i,j) = A(ii,i,j) + A(ii+1,i,j) + A(ii+2,i,j); 
       %B(i,j) = A(ii,i,j); 
      end 
     end 
    end 
    k = k+1; 
    filename = sprintf('/Users/Alberto/Desktop/Midi/Edited_images/Despeckled_images/despeckled_image_%03i.tif',k); 
    %Now we rotate the matrix 
    B_rot=rot90(B); 
    imwrite(B_rot, filename); 
    %imwrite(uint16(B_rot), filename); 
    %Now we subtract the OB median 
    B_final_rot = double(B_rot) - 3*double(OB_median_rot); 
    filename = sprintf('/Users/Alberto/Desktop/Midi/Edited_images/Final_image/final_image_%03i.tif',k); 
    imwrite(uint16(B_final_rot), filename); 
end 

回答

1

可由uint16数据类型来表示的最大整数是

>> a=100000; uint16(a) 

ans = 

    65535 

为了克服这种限制就需要重新调整数据作为double类型和调整范围(图像对比度),以同意保存为uint16之前的uint16数据类型施加的限制。