Effacer les filtres
Effacer les filtres

Pasting multiple images, but gets cut off (PLEASE HELP!)

1 vue (au cours des 30 derniers jours)
Jane
Jane le 3 Déc 2013
Réponse apportée : Jane le 3 Déc 2013

Hello,

I am pasting multiple images onto a black image; however, some of the images are no longer shown at ~the 4806 pixel matrix column. You should be able to see 10 leg segments, but here you can only see 3 and a half (the 4th image is cut). Please help! Why is this happening? Thanks!

code adapted from Image Analyst.

if true
  % %% ALIGN ALL LEG SEGMENTS
clc;    % Clear the command window.
close all;  % Close all figures (except those of imtool.)
imtool close all;  % Close all imtool figures.
clear;  % Erase all existing variables.
workspace;  % Make sure the workspace panel is showing.
fontSize = 20;
format compact;
%
grayImage = imread('Blackout.png');
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[I1R I1C numberOfColorBands] = size(grayImage);
%
% imread smaller image
rotatedImage2=imread('rotCoxa.png');
[I2R I2C] = size(rotatedImage2);
rotatedImage3=imread('rotTrochanter.png');
[I3R I3C] = size(rotatedImage3);
rotatedImage4=imread('rotFemur.png');
[I4R I4C] = size(rotatedImage4);
rotatedImage5=imread('rotTarsus5.png');
[I5R I5C] = size(rotatedImage5);
rotatedImage6=imread('rotTarsus4.png');
[I6R I6C] = size(rotatedImage6);
rotatedImage7=imread('rotTarsus3.png');
[I7R I7C] = size(rotatedImage7);
rotatedImage8=imread('rotTarsus2.png');
[I8R I8C] = size(rotatedImage8);
rotatedImage9=imread('rotTarsus1.png');
[I9R I9C] = size(rotatedImage9);
rotatedImage10=imread('rotTarsus0.png');
[I10R I10C] = size(rotatedImage10);
%
% Paste it onto the original image
% Coxa
x = 1;
y = I1R/2;
% Determine the pasting boundaries.
r1 = int32(y);
c1 = int32(x);
r2 = r1 + I2R - 1;
r2 = min([r2 I1R]);
c2 = c1 + I2C - 1;
c2 = min([c2, I1R]);
plot([c1 c2 c2 c1 c1], [r1 r1 r2 r2 r1], 'r-');
% Paste as much of croppedImage as will fit into the original image.
grayImage(r1:r2, c1:c2) = rotatedImage2(1:(r2-r1+1), 1:(c2-c1+1));
%
% Trochanter
x = I2C;
y = I1R/2+I2R/2-I3R/2;
% Determine the pasting boundaries.
r1 = int32(y);
c1 = int32(x);
r2 = r1 + I3R - 1;
r2 = min([r2 I1R]);
c2 = c1 + I3C - 1;
c2 = min([c2, I1R]);
plot([c1 c2 c2 c1 c1], [r1 r1 r2 r2 r1], 'r-');
% Paste as much of croppedImage as will fit into the original image.
grayImage(r1:r2, c1:c2) = rotatedImage3(1:(r2-r1+1), 1:(c2-c1+1));
%
%Femur
x = I2C+I3C;
y = I1R/2+I2R/2-I4R/2;
% Determine the pasting boundaries.
r1 = int32(y);
c1 = int32(x);
r2 = r1 + I4R - 1;
r2 = min([r2 I1R]);
c2 = c1 + I4C - 1;
c2 = min([c2, I1R]);
plot([c1 c2 c2 c1 c1], [r1 r1 r2 r2 r1], 'r-');
% Paste as much of croppedImage as will fit into the original image.
grayImage(r1:r2, c1:c2) = rotatedImage4(1:(r2-r1+1), 1:(c2-c1+1));
%
%Tarsus 5
x = I2C+I3C+I4C;
y = I1R/2+I2R/2-I5R/2;
% Determine the pasting boundaries.
r1 = int32(y);
c1 = int32(x);
r2 = r1 + I5R - 1;
r2 = min([r2 I1R]);
c2 = c1 + I5C - 1;
c2 = min([c2, I1R]);
plot([c1 c2 c2 c1 c1], [r1 r1 r2 r2 r1], 'r-');
% Paste as much of croppedImage as will fit into the original image.
grayImage(r1:r2, c1:c2) = rotatedImage5(1:(r2-r1+1), 1:(c2-c1+1));
%
%Tarsus 4
x = I2C+I3C+I4C+I5C;
y = I1R/2+I2R/2-I6R/2;
% Determine the pasting boundaries.
r1 = int32(y);
c1 = int32(x);
r2 = r1 + I6R - 1;
r2 = min([r2 I1R]);
c2 = c1 + I6C - 1;
c2 = min([c2, I1R]);
plot([c1 c2 c2 c1 c1], [r1 r1 r2 r2 r1], 'r-');
% Paste as much of croppedImage as will fit into the original image.
grayImage(r1:r2, c1:c2) = rotatedImage6(1:(r2-r1+1), 1:(c2-c1+1));
%
%Tarsus 3
x = I2C+I3C+I4C+I5C+I6C;
y = I1R/2+I2R/2-I7R/2;
% Determine the pasting boundaries.
r1 = int32(y);
c1 = int32(x);
r2 = r1 + I7R - 1;
r2 = min([r2 I1R]);
c2 = c1 + I7C - 1;
c2 = min([c2, I1R]);
plot([c1 c2 c2 c1 c1], [r1 r1 r2 r2 r1], 'r-');
% Paste as much of croppedImage as will fit into the original image.
grayImage(r1:r2, c1:c2) = rotatedImage7(1:(r2-r1+1), 1:(c2-c1+1));
%
%Tarsus 2
x = I2C+I3C+I4C+I5C+I6C+I7C;
y = I1R/2+I2R/2-I8R/2;
% Determine the pasting boundaries.
r1 = int32(y);
c1 = int32(x);
r2 = r1 + I8R - 1;
r2 = min([r2 I1R]);
c2 = c1 + I8C - 1;
c2 = min([c2, I1R]);
plot([c1 c2 c2 c1 c1], [r1 r1 r2 r2 r1], 'r-');
% Paste as much of croppedImage as will fit into the original image.
grayImage(r1:r2, c1:c2) = rotatedImage8(1:(r2-r1+1), 1:(c2-c1+1));
%
%Tarsus 1
x = I2C+I3C+I4C+I5C+I6C+I7C+I8C;
y = I1R/2+I2R/2-I9R/2;
% Determine the pasting boundaries.
r1 = int32(y);
c1 = int32(x);
r2 = r1 + I9R - 1;
r2 = min([r2 I1R]);
c2 = c1 + I9C - 1;
c2 = min([c2, I1R]);
plot([c1 c2 c2 c1 c1], [r1 r1 r2 r2 r1], 'r-');
% Paste as much of croppedImage as will fit into the original image.
grayImage(r1:r2, c1:c2) = rotatedImage9(1:(r2-r1+1), 1:(c2-c1+1));
%
%Tarsus 0
x = I2C+I3C+I4C+I5C+I6C+I7C+I8C+I9C;
y = I1R/2+I2R/2-I10R/2;
% Determine the pasting boundaries.
r1 = int32(y);
c1 = int32(x);
r2 = r1 + I10R - 1;
r2 = min([r2 I1R]);
c2 = c1 + I10C - 1;
c2 = min([c2, I1R]);
plot([c1 c2 c2 c1 c1], [r1 r1 r2 r2 r1], 'r-');
% Paste as much of croppedImage as will fit into the original image.
grayImage(r1:r2, c1:c2) = rotatedImage10(1:(r2-r1+1), 1:(c2-c1+1));
%
imshow(grayImage);
axis on;
title('Region that you defined pasted onto original', 'FontSize', fontSize);
%
% Save rotated image
imwrite(grayImage, 'alignedImage.png');
end

Réponse acceptée

Jane
Jane le 3 Déc 2013
I figured it out! I just need to remove the r2 = min() and c2 = min() portion of the code and it worked beautifully.
Thank you all!

Plus de réponses (1)

Walter Roberson
Walter Roberson le 3 Déc 2013
That code will only paste images to the maximum width of the original image 'Blackout.png'
  1 commentaire
Jane
Jane le 3 Déc 2013
Thanks! Yes, but the width will fit all 10 images.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by