I am trying for crop an image in to two equal parts using for loop but not getting correct ans.

clc; clear all; close all;
input= imread('120kv x1.25mA(56000)15cm.bmp'); figure(1),imshow(input); a=im2double(input); [x, y, z]=size(a);
y1=round(y/2);
% new=a; for i=1:x; for j=1:z; for k=1:y1; new(x, y1, z)=a(x, y, z); end end end figure, imshow(new);
% new=a; for i=1:x; for j=1:z; for k=1:y1; new1(x,y1,z)=a(x, y1+1, z); end end end figure, imshow(new1);

 Respuesta aceptada

Don't use input as the name of your image because it's already the name of a built-in function. You don't need a for loop. Just use regular indexing:
[rows, columns, numberOfColorChannels] = size(rgbImage);
middleCol = floor(columns/2);
leftHalf = rgbImage(:, 1:middleCol, :);
rightHalf = rgbImage(:, (middleCol+1):end, :);

4 comentarios

thanks, but actually i want to crop image equally for image registration, this is not working correctly for image registration.
You said you want to "crop an image in to two equal parts" and didn't say anything about registration. Look up registration in the help for several functions that do that in the Image Processing Toolbox.
Is it possible to crop image using for loop?
Yes, but you wouldn't want to do that.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Image Processing Toolbox en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 6 de Abr. de 2015

Comentada:

el 7 de Abr. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by