How can i remove borders image?

3 visualizaciones (últimos 30 días)
Ehsan R
Ehsan R el 18 de Abr. de 2013
Comentada: DGM el 5 de Mzo. de 2024
hi
i have a picture containing a figure(digit). i'd like to remove the borders of the picture from all four direction so that just the figure is left(no borders).
meanwhile please don'tuse imclearborder and imcrop.
  1 comentario
Image Analyst
Image Analyst el 18 de Abr. de 2013
Editada: Image Analyst el 18 de Abr. de 2013
Why do you say that? Why "please don't use" the functions that can accomplish what you want to accomplish? It just doesn't make sense. Do you want to get the job done or not? Try posting your image to snag.gy or tinypic.com.

Iniciar sesión para comentar.

Respuestas (2)

Image Analyst
Image Analyst el 18 de Abr. de 2013
Your image did not come through for me - for some reason that site is banned by my company. Try the command imclearborder() in the Image Processing Toolbox. Or just use imcrop() or extraction
subimage = fullImage(row1:row2, column1:column2);

Guilherme Freire Roberto
Guilherme Freire Roberto el 5 de Mzo. de 2024
Not the fanciest solution, but this worked for me:
%Remove borders from upper rows
checkRow = 0;
while(checkRow == 0)
if any(IMG(:,1))
checkRow = 1;
else
IMG = IMG(:,2:end);
end
end
%Remove borders from bottom rows
checkRow = 0;
while(checkRow == 0)
if any(IMG(:,size(IMG,2)))
checkRow = 1;
else
IMG = IMG(:,1:end-1);
end
end
%Remove borders from left columns
checkColumn = 0;
while(checkColumn == 0)
if any(IMG(1,:))
checkColumn = 1;
else
IMG = IMG(2:end,:);
end
end
%Remove borders from right columns
checkColumn = 0;
while(checkColumn == 0)
if any(IMG(size(IMG,1),:))
checkColumn = 1;
else
IMG = IMG(1:end-1,:);
end
end
  1 comentario
DGM
DGM el 5 de Mzo. de 2024
It works, but if you're already familiar with any(), you can simplify a lot.
% find ROI geometry
inpict = any(inpict,3); % collapse channels
mkr = any(inpict,2); % find rows with nonzero elements
mkc = any(inpict,1); % find cols with nonzero elements
r1 = find(mkr,1,'first');
r2 = find(mkr,1,'last');
c1 = find(mkc,1,'first');
c2 = find(mkc,1,'last');
% crop original image to extents
inpict = inpict(r1:r2,c1:c2,:); % all channels

Iniciar sesión para comentar.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by