Automatic cropping

I have a cbir system and the output results depends on the cropping of the query image boundary and has to be the same as the cropping of the image boundary in the database. so i was wondering is there a way to crop an image automatically. e.g i do edge detection which gives outlines of the image. i want to crop a certain part of the image automatically. image is a numberplate i want automatic cropping of the image to only include the characters of the number plate and not any other extra little characters unless necessary if the letters mix in with the tiny characters.
an example would be good.
i.e.
this is the start of my code
a=imread(numberplate.jpg);
gr=rgb2gray(a);
bw=im2bw(gr);
edge=edge(bw,'canny',[0.15, 0.3])
crp=imcrop(edge)
This is manual i need automatic.
thanks

Respuestas (6)

Walter Roberson
Walter Roberson el 8 de Abr. de 2011

0 votos

Do you have code now to detect the portion of the image which is the license plate?
Sean de Wolski
Sean de Wolski el 8 de Abr. de 2011

0 votos

Copy and paste that into a script||function and it'll be automatic.

16 comentarios

Walter Roberson
Walter Roberson el 8 de Abr. de 2011
Assuming, of course, that numberplate is a structure with a field named jpg which contains a string which is the name of an image file.
Sean de Wolski
Sean de Wolski el 8 de Abr. de 2011
Very, true. But he said it works; it just isn't automated.
Jack
Jack el 10 de Abr. de 2011
Movida: DGM el 11 de Feb. de 2023
Exactly it is not automated. the user has to do the cropping manually.
i want an automatic cropping without any user intervention of the boundary.
something like.
loop through the edge detected image where it is black value zero for the boundary around the image and use that as the crop boundary.
Sean de Wolski
Sean de Wolski el 11 de Abr. de 2011
Movida: DGM el 11 de Feb. de 2023
First off, don't overwrite the MATLAB function EDGE when you name the variable EDGE!
Could you just find the bounding box of the edge image using regionprops and extract it/save it etc? The rest is just manipulating the string for imread. You could do that with a variety of ways but you haven't made anything clear to us as to how what you want automated.
As Walter and I said before; assuming that your above code works (which we agreed it probably doesn't since numberplate.jpg should be in single quotes); everything else IS automated if you put it in a script and run it.
Jack
Jack el 11 de Abr. de 2011
Movida: DGM el 11 de Feb. de 2023
firstly:i was rushing so i forgot the single quotes but that is not the problem.
Sorry for not explaining well
here it is.
input is numberplate image. i want to read it, convert it to gray scale. detect edges using canny method. crop it using imcrop. but the thing i need is the boundary around the image to use in the imcrop function so the user doesn't have to manualy crop the image.
these are the input images they need to be gray scaled and cropped to only include the letters and numbers only minimze any other lines interfering as seen on image 2. i want to find the boundary coordinates to crop.
i hope you understand what i want to crop. my code does work but that only tells the user to manually crop the image i want the cropping process to be automatic
i will try regionprops
Jack
Jack el 13 de Abr. de 2011
Movida: DGM el 11 de Feb. de 2023
i tried using region props but i don't understand how i would get the boundary of interest from the numberplate using regionprops. please help in explaining how to get the boundary coordinates around the number plate.
Sean de Wolski
Sean de Wolski el 13 de Abr. de 2011
Movida: DGM el 11 de Feb. de 2023
doc regionprops
look at the explanation for BoundingBox.
ceil() the first two entries as the minimum x,y and then add the the third and fourth to the first and second respectively to get the maximum.
Extract with:
Icropped = I(ymin:ymax,xmin:xmax,:);
Jack
Jack el 14 de Abr. de 2011
Movida: DGM el 11 de Feb. de 2023
im really confused i don't understand.
with bounding box i get a lot of coordinates.
i do something like a=regionprops(image);
reg=a.boundingbox;
this results in more than one answer.
is there an example or demo on the regionprops thanks
Sean de Wolski
Sean de Wolski el 14 de Abr. de 2011
Movida: DGM el 11 de Feb. de 2023
That will give the coordinates for the boundingbox of each object. Read the documentation!!
Jack
Jack el 18 de Abr. de 2011
Movida: DGM el 11 de Feb. de 2023
i did read it, the explanation is only a few lines saying boundbox gives coordinates of xmin ymin and xwidth ywidth.
thats it
here is what i have tried
e=edge(a,'canny',[0.15,0.3]); reg=regionprops(e,'BoundingBox');
reg= 43x1 struct
so i know it has found 43 different bounding coordinates.
i then did reg.BoundingBox
xmin=ceil(ans(1,1)); ymin=ceil(ans(1,2)); xwidth=(ans(1,1)+ans(1,3)); ywidth=(ans(1,2)+ans(1,4));
i get a small area
then i tried after icropped=i(xmin,ymin,xwidth,ywidth) error=too many inputs
help would be appreciated thanks
Walter Roberson
Walter Roberson el 18 de Abr. de 2011
Movida: DGM el 11 de Feb. de 2023
At your level of understanding, you should never name a structure followed by a field, only a structure followed by an index followed by a field. reg(K).BoundingBox for K from 1 to length(reg)
You might perhaps be wanting to find the bounding box that encloses all of the bounding boxes you found through edge detection; if so then you should be thinking about min() and max().
There _are_ some useful things you can do with naming a structure name and then a field name with no index, but your first order of duty is to get the code working; optimization can come afterwards.
Jack
Jack el 20 de Abr. de 2011
Movida: DGM el 11 de Feb. de 2023
i did a loop to try and crop the image using all the coordinates from boundingbox.
i wrote
for i=1:length(reg) %in this case length of reg is 43
xmin=reg(k).BoundingBox(1);
ymin=reg(k).BoundingBox(2);
xwidth=reg(k).BoundingBox(3);
ywidth=reg(k).BoundingBox(4);
cr=imcrop(e,'canny',[0.15,0.3]);
imshow(cr);
end
for image 1 when k=4 the whole numberplate was captured including the borders and for image 2 it was when k=3 is it possible to get only the characters not the whole numberplate with the little flag if not i guess it is ok how do i stop the loop when i get that numberplate image boundingbox
note: ceil() the first two entries as the minimum x,y and then add the the third and fourth to the first and second respectively to get the maximum. Extract with: Icropped = I(ymin:ymax,xmin:xmax,:);
do i do ceil of BoundingBox(1)and(2) for x and y min get x and y max by adding BoundingBox(1) to (3) and (2) to (4) respectively
then icrop=i(ymin:ymax,xmin:xmax,:);
is this what was meant by that statement
thanks
Sean de Wolski
Sean de Wolski el 20 de Abr. de 2011
Movida: DGM el 11 de Feb. de 2023
Assuming that BoundingBox is 1x4 (i.e. it was a 2d image) then this looks correct to me. What results did you attain? Did it work?
Jack
Jack el 22 de Abr. de 2011
Movida: DGM el 11 de Feb. de 2023
but i don't want the user to do any work besides loading image the cropping should be automatic. can someone help. regarding my previous post.
thanks
Jack
Jack el 22 de Abr. de 2011
Movida: DGM el 11 de Feb. de 2023
i tried what you said
when i reach up to reg=regionprops('BoundingBox')
you said to ceil the first two entries i ddn't know which of the 52 coordinates do i look at.
im guessing its is the bound that captures the whole numberplate. through the loop i said.
but when i ceil(first 2 entries i.e. xmin, ymin) then add entries 1 and 2 to 3 and 4 respectively after the ceil func.
its ok up this point but when i do icrop=i(ymin:ymax,xmin:max,:) it says index esceeds matrix dimension or something. if i do Capital I(ymin:ymax,xmin:xmax,:) says undefine function or variable I
i need help with this thanks
LAXMI NARAYAN SONI
LAXMI NARAYAN SONI el 7 de Mayo de 2017
Movida: DGM el 11 de Feb. de 2023
Yes this is the right way.... U also have to be use a loop.

Iniciar sesión para comentar.

priya
priya el 20 de Abr. de 2011
Editada: DGM el 11 de Feb. de 2023

0 votos

I guess this should work... (not sure though). when you do imcrop() you should be able to right click and get the co-ordinates of the image which you have selected for croping.
%ime1 = findimage();
a=imread(numberplate.jpg);
gr=rgb2gray(ime1);
% BW=im2bw(gr);
edit=edge(gr,'canny',[0.15, 0.3])
im1 = imcrop(edit,[100.5 101.5 456 87]); imshow(im1);
LAXMI NARAYAN SONI
LAXMI NARAYAN SONI el 7 de Mayo de 2017
Editada: Walter Roberson el 14 de Mayo de 2017

0 votos

if u have a yellow color no. plate then u can use color based cropping... ike u can crop only yellow color. as simple as that.
clc
clear all
close all
a = imread('car3.jpg');
%b=imshow(a)
red = a(:,:,1);
green = a(:,:,2);
blue = a(:,:,3);
figure,imshow(red);
figure,imshow(green);
figure,imshow(blue);
%d = impixel(a);
i=size(a)
for c=0:i
if a(:,:,1)>13 or <255
if a(:,:,2)>0 or <201
if a(:,:,3)>0 or <104
d = imcrop(a);
figure,imshow(d)
end
end
end
end

1 comentario

DGM
DGM el 11 de Feb. de 2023
Editada: DGM el 12 de Feb. de 2023
It's a good thing that code isn't even valid, because even in concept, it would accomplish nothing worth the cost of execution.
Consider a 1000x1000x3 RGB image. For each element in the array, you ostensibly want to:
  1. test to see if the entire image is within a prismatic volume within the RGB color space
  2. if it is, display the full image in a window and request that the user interactively select a region with the mouse, right click, and then select "crop image" from a dropdown menu
  3. display the cropped region and then discard it
So either the first test fails and the code does literally nothing but spend time warming your CPU, or you're going to make the user do the exact same manual task three million times. Like I said, it's a good thing that it's not valid syntax.

Iniciar sesión para comentar.

Samreen kayani
Samreen kayani el 9 de En. de 2019

0 votos

i want to segment each letter individually but bounding box divid 1 into 11 instead of 1.12 my answere is 11.112

Categorías

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

Preguntada:

el 8 de Abr. de 2011

Editada:

DGM
el 12 de Feb. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by