How to combine image patches into single image.

9 次查看(过去 30 天)
  3 个评论
Rik
Rik 2020-12-18
These look like subplots. Do you have the original images used for each subimage?

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2020-12-18
If that image is REALLY your image like you say, and you didn't just show us a figure window using subplot(), then you can do this:
% Demo by Image Analyst, December, 2020.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clearvars;
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
fprintf('Beginning to run %s.m ...\n', mfilename);
%-----------------------------------------------------------------------------------------------------------------------------------
% Read in image.
folder = [];
baseFileName = 'image.png';
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
[rows, columns, numberOfColorChannels] = size(rgbImage)
% Display the test image full size.
subplot(2, 2, 1);
imshow(rgbImage, []);
axis('on', 'image');
caption = sprintf('Original Image : "%s"', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Set up figure properties:
% Enlarge figure to full screen.
hFig1 = gcf;
hFig1.Units = 'Normalized';
hFig1.WindowState = 'maximized';
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
hFig1.Name = 'Demo by Image Analyst';
% Mask to find the black part on the left.
[r, g, b] = imsplit(rgbImage);
mask = (r == 240) & (g == 240) & (b == 240);
% Display the image.
subplot(2, 2, 2);
imshow(mask, []);
axis('on', 'image');
title('Mask Image', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
% Find columns that are all 1.
columnsToDelete = all(mask, 1);
% Find rows that are all 1.
rowsToDelete = all(mask, 2);
% Delete columns
r(:, columnsToDelete) = [];
g(:, columnsToDelete) = [];
b(:, columnsToDelete) = [];
% Delete columns
r(rowsToDelete, :) = [];
g(rowsToDelete, :) = [];
b(rowsToDelete, :) = [];
% Rebuild rgbImage from separate color channels.
rgbImage = cat(3, r, g, b);
subplot(2, 2, 3);
imshow(rgbImage, []);
axis('on', 'image');
title('Final Image', 'FontSize', fontSize, 'Interpreter', 'None');
fprintf('Done running %s.m ...\n', mfilename);
  1 个评论
Image Analyst
Image Analyst 2020-12-21
Not until you add comments - a LOT of them. It would take me hours to figure out what the code above does without comments. Plus, it's not even properly indented (control-a, control-i in MATLAB). When one adds comments, one often discovers the source/cause of the error. In the meantime, or if you refuse to add comments, see the link below:

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by