使用Matlab进行图像处理 - 强度和tif图像

时间:2013-10-17 11:09:29

标签: image matlab max tiff

我必须分析一组图像,这些是我需要执行的操作:

  1. 求和另一组图像(在代码中称为开放光束),计算中位数并将其旋转90度;
  2. 加载一组图片,列在文件“list.txt”;
  3. 图像以3组为单位收集。对于每组,我想生成一个图像,其强度值是图像中位数高于某个阈值的3倍,否则等于强度值的总和;
  4. 对于每组三幅图像,从组合图像中减去开放光束中值(以1计算)(以3计算)。
  5. 考虑到使用上述过程产生的一个tif,我得到的最大值是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 个答案:

答案 0 :(得分:1)

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

>> a=100000; uint16(a)

ans =

  65535

要绕过此限制,您需要将数据重新调整为double类型,并在保存为{{uint16之前调整范围(图像对比度)以符合uint16数据类型施加的限制1}}。