Image Processing along diagonal. I am a student and beginning learner of matlab, I have study some code and do not understand the meaning also the syntax of the code(the second for loop), can anybody help me? Thank you.
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I = imread('lenna.tiff'); % read the image to variable I
[x y z]=size(I); % read image size to variable x, y, z
R=zeros(x,y,z); % initialize the result matrix
% copy the original block of data
for n = 1:x
R(n,1:n,:)=I(n,1:n,:);
end
% copy the inverted block of data
for n = 1:x
n
R(1:n,n,:)=I(n,1:n,:);
end
R=uint8(R); % convert it to unsiged integer
imshow(R); % display the image
0 commentaires
Réponses (1)
Image Analyst
le 26 Nov 2012
That is ridiculous code - wasteful and repetitive. I recommend that you run fast and far away from that code and not use it. And whoever wrote it needs to take a refresher course in MATLAB programming. Instead you should look at the examples in the help documentation or check out my File Exchange.
2 commentaires
Image Analyst
le 28 Nov 2012
Well I guess it does do that. Perhaps if we rename some variables and put in some comments it will help you understand.
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.
format longg;
format compact;
fontSize = 20;
I = imread('peppers.png'); % read the image to variable I
[Rows columns numberOfColorChannels]=size(I); % read image size to variable x, y, z
% Crop to a square
I = I(1:Rows, 1:Rows, :); % Assumes x < y.
[Rows columns numberOfColorChannels]=size(I); % Get new square dimensions.
R=zeros(Rows,columns,numberOfColorChannels); % initialize the result matrix
subplot(2, 2, 1);
imshow(I);
title('Original Image', 'FontSize', fontSize);
% Copy a triangle from the original image.
for n = 1:Rows
R(n,1:n,:)=I(n,1:n,:);
end
subplot(2, 2, 2);
imshow(uint8(R));
title('Initial half of the R Image', 'FontSize', fontSize);
% Paste the triangle into the other triangle.
for n = 1:Rows
n
R(1:n,n,:)=I(n,1:n,:);
end
R=uint8(R); % convert it to unsiged integer
subplot(2, 2, 3);
imshow(R);
title('Final R Image', 'FontSize', fontSize);
% Go all the way around
R360 = [R imrotate(R, 270); imrotate(R, 90) imrotate(R, 180) ];
subplot(2, 2, 4);
imshow(R360);
title('R360 Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
Voir également
Catégories
En savoir plus sur Explore and Edit Images with Image Viewer App dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!