我正在嘗試運行以下代碼來分析多個不同目錄中的多個 .tif 影像。運行代碼時,給出的數字是空白的,然后是第 49 行的錯誤“必須為壓縮腐蝕提供 M”。我首先意識到我在代碼中將 .tif 拼寫為 .tiff,然后我對其進行了更改。然后我決定通過創建一個 Tiff 物件并將影像路徑包裝在 tiff 物件中來讀取一個 .tif 影像。控制臺報錯,說檔案無法打開。
代碼
%% Import Spheroid Directory
Path = 'C:\Users\18606\OneDrive\Documents\Spheroids For Brandon\Spheroids For Brandon\1-8WT';
if ~isfolder(Path)
errorMsg = sprintf('Error: The following folder does not exist:\n%s',Path);
uiwait(warndlg(errorMsg));
return;
end
%% Iterate over each subfolder with .tiff images
Content = fullfile(Path, '*.tif'); % Read Experiment directory with .tiff images
subFold = dir(Content);
imageFiles = []; % Create empty list array
for k = 1:length(subFold)
F = fullfile(Path, subFold(k).name); % For k subfolders, output the full file name and open each subfolder
fileID = fopen(F);
imageFiles{end 1} = fopen(fileID,'%s\n'); % Append fileID to imageFiles list
fclose(fileID);
end
disp(imageFiles(k)) % Display the image files for analysis
%% Image preprocessing
%Divide image "obj" into its respective RGB intensities
red = imageFiles(:,:,1);
green = imageFiles(:,:,1);
blue = imageFiles(:,:,1);
figure(1)
subplot(2,2,1); imshow(imageFiles); title('Original Image')
subplot(2,2,2); imshow(imageFiles); title('Red Plane')
subplot(2,2,3); imshow(imageFiles); title('Green Plane');
subplot(2,2,4); imshow(imageFiles); title('Blue Plane');
%Threshold the blue plane
figure(2)
level = 0.37;
bw2 = imbinarize(blue, level);
subplot(2,2,1); imshow(bw2); title('Blue plane threshold');
%% Image preprocessing continued
fill = imfill(bw2,'holes');
subplot(2,2,2); imshow(fill); title('Holes filled')
%Remove any blobs on border of image
clear = imclearborder(fill);
subplot(2,2,3); imshow(clear); title('Blobs removed');
%Remove blobs smaller than 7 pixels across
se = strel('disk',7);
open = imopen(fill, se);
subplot(2,2,4); imshow(open); title('Removed small blobs');
%% Measure the number of pixels in Image
%numberOfPixels = numel(inputFile);
%[pixelCounts, grayLevels] = imhist(inputFile);
%numberofPixels = sum(pixelCounts);
%% Measure the distance of migration in micromolars
diameter = regionprops(open, 'MajorAxisLength');
%Show result
figure(3)
imshow(imageFiles)
d = imdistline; %Includes a line to physically measure the object
錯誤資訊
>> RawData
Error using images.internal.morphop>ParseInputs
M must be provided for packed erosion.
Error in images.internal.morphop (line 23)
unpacked_M,mex_method] = ParseInputs(varargin{:});
Error in imerode (line 87)
B = images.internal.morphop(A,se,'erode',mfilename,varargin{:});
Error in imopen (line 73)
outputImage = imdilate(imerode(inputImage,se,'ispacked',M),se,'ispacked',M);
Error in RawData (line 49)
open = imopen(fill, se);
我有一種預感,檔案路徑被錯誤地讀取,但程式正在讀取一些東西,否則它會拋出代碼中指定的錯誤。我很感激我能在這件事上得到任何幫助。
uj5u.com熱心網友回復:
您的代碼中有很多沒有意義的東西。
fileID = fopen(F);
imageFiles{end 1} = fopen(fileID,'%s\n'); % Append fileID to imageFiles list
這將打開檔案,然后將其檔案名放入imageFiles{end 1}. 這和剛才做的一樣imageFiles{end 1} = F,但是更混亂。
稍后,您可以像使用imageFiles影像一樣使用它:
red = imageFiles(:,:,1);
但它不是影像,它是具有一組檔案的名稱(帶路徑)的元胞陣列!
imshow(imageFiles)將加載該陣列中的影像,并將它們顯示給您。但除此之外,您永遠不會加載影像,因此您所做的所有計算都是在檔案名稱而不是像素資料上進行的。
你想用來imread加載像素資料。不要fopen檔案,只有imread它們。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/478657.html
上一篇:從影像中洗掉黃色矩形
下一篇:Photoshop中的每像素邏輯
