Borrar filtros
Borrar filtros

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 visualizaciones (últimos 30 días)
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

Respuestas (1)

Image Analyst
Image Analyst el 26 de Nov. de 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 comentarios
Trevor
Trevor el 28 de Nov. de 2012
Editada: Trevor el 28 de Nov. de 2012
The code were given by the teaching associate in the university. He gave this sample for us to self learning and wants us to do a Kaleidoscope. I still haven't got any idea >_<, do you know any websites have matlab sample code about kaleidoscope that can give me a reference. I can't find any. <http://3.bp.blogspot.com/-dXAgV1Rea_M/T2o2nhrd2fI/AAAAAAAAAC8/p3uWgA2w-Kc/s1600/kaleidoscope-view.jpg>Thanks.
Image Analyst
Image Analyst el 28 de Nov. de 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]);

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by