필터 지우기
필터 지우기

I am struggling to get this code to work.

조회 수: 1 (최근 30일)
Martin Olowe
Martin Olowe 2021년 8월 4일
댓글: Image Analyst 2021년 8월 5일
Im unsure of which parameters to change to stitch the image to get the code to work. I have attached the 2 codes in the question as well as a sample set of images

답변 (2개)

Image Analyst
Image Analyst 2021년 8월 4일
Try this:
clc; % Clear the command window.
fprintf('Beginning to run %s.m ...\n', mfilename);
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
%Division Option
DO=8;
%Defect Color Threshold
colorThreshold=60;
% Specify folder.
folder = fullfile(pwd, 'Image sample');
% Assume all files in folder are to be stitched together.
defaultValues = {'8', '1'};
[pics] = inputdlg({'How many pictures were taken in x direction?','How many pictures were taken in y direction?'},...
'Size of concacenated image', [1 51; 1 51], defaultValues);
x=double(string(pics{1,1}));
y=double(string(pics{2,1}));
% Get all filenames:
filePattern = fullfile(folder, '*.tif');
fileList = dir(filePattern);
fileNames = {fileList.name}
loopCounter = 1;
fullFileName = fullfile(folder, fileNames{loopCounter});
thisImage = imread(fullFileName);
[rows, columns, numberOfColorChannels] = size(thisImage);
% Preallocate output image.
stitchedImage = zeros(y * rows, x * columns);
% Do the stitching.
for row = 1 : y
thisRow = (row - 1) * rows + 1;
for col = 1 : x
thisColumn = (col - 1) * columns + 1;
% Read in this image.
fullFileName = fullfile(folder, fileNames{loopCounter});
thisImage = imread(fullFileName);
thisImage=double(thisImage);
% Paste onto canvass.
stitchedImage(thisRow : (thisRow + rows - 1), thisColumn : (thisColumn + columns -1), :) = thisImage;
% Increment file counter.
loopCounter = loopCounter + 1;
end
end
subplot(2, 1, 1);
imshow(stitchedImage, [])
impixelinfo
title('Original Stitched Image', 'FontSize', 17);
axis('image', 'on');
binaryImage = stitchedImage < colorThreshold;
subplot(2, 1, 2);
imshow(binaryImage)
axis('image', 'on');
g = gcf;
g.WindowState = 'maximized';
% Compute area fraction.
areaFraction = nnz(binaryImage) / numel(binaryImage)
caption = sprintf('Binary Image. The Area fraction for a threshold of %.1f is %.4f.', colorThreshold, areaFraction);
title(caption, 'FontSize', 17);
message = sprintf('The Area fraction for a threshold of %.1f is %.4f.', colorThreshold, areaFraction);
fprintf('%s\n', message);
fprintf('Done running %s.m.\n', mfilename);
uiwait(helpdlg(message));
  댓글 수: 2
Martin Olowe
Martin Olowe 2021년 8월 4일
willi need to change any variables? I have images consisting of 153 tiles to be stitched
Image Analyst
Image Analyst 2021년 8월 5일
You'll need to change the number of rows and columns of course. And I haven't tested it for the case where you have multiple rows and you only have enough images to fill up a partial row. So that may need to be checked and made more robust. Just give it a try and adapt as needed.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2021년 8월 5일
You might be interested in using montage(). The output of montage() is an image() object that you can get the CData for, and the CData will be the composite image.
  댓글 수: 1
Image Analyst
Image Analyst 2021년 8월 5일
Yes, or imtile() introduced in r2018b.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Agriculture에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by