How to detect a specific image object and the crop object from the input images
5 views (last 30 days)
Show older comments
Muhammad Irfan
on 13 Jul 2018
Commented: Image Analyst
on 22 Jul 2018
Hi, I have solar panel cell images taken from various resolution cameras, I want to detect a cell in the input Image and find out that specific object(cell) inside the input image, How i can do this?? I need to crop cell once it is detected, here is an example, I need to separate out cells based on black rectangle around cell.
0 Comments
Accepted Answer
Image Analyst
on 15 Jul 2018
Muhammad:
Attached is a full demo that works with your image that you posted. It assumes that the band height is fixed - all tiles within one horizontal band seem to be within the same pair of row numbers. Then it gets the average horizontal profile and looks for little dark lines that separate the 10 different tiles. Then it goes through the band cropping out each tile and writing it to disk. Below is a screen shot after it has found the last tile in band #6, but the screen will update at every single tile. There are tons of comments and helpful pictures to show you what it's doing. Let me know if this works for you. If it doesn't work for some other image, post the image it fails with so we can determine why its different than the only image you posted so far.
7 Comments
Image Analyst
on 17 Jul 2018
You could ask the user with inputdlg() how many rows are in this image, or else you could look at the average vertical profile, then smooth it and subtract it to find the peaks - much like I already did to find the divisions horizontally. The code is already in there, just copy it and adapt it to work on the vertical profile instead of the horizontal profile.
More Answers (3)
Image Analyst
on 14 Jul 2018
Don't you have these 60 images "taken from various resolution cameras"?
Or is all you have one gigantic image where someone unfortunately stitched them all together? And if so, why can't you just use imcrop() to chop the image into 10 columns and 6 rows?
Matt J
on 15 Jul 2018
Edited: Matt J
on 15 Jul 2018
My strategy would be as follows. I demonstrate with a somewhat cropped and binned version (attached) of your original image. First do some enhancement of the image to emphasize the horizontal and vertical lines over the background,
A=imread('Panels.png');
A=medfilt2(A,[10,10])-A;
A([1,end],:)=max(A(:));
A(:,[1,end])=max(A(:));
%%enhance columns
B=A; d=ones(10,1);
B=imerode(B,d);
%%enhance rows
C=A;
C=imerode(C,d.');
D=(B+C); %combine
Then, because you know the approximate dimensions of the cells, you can pick out a box enclosing the first cell
OneCell=D(1:130,1:130);
figure(1);
imagesc(OneCell)
Then you take row-wise and column-wise means of this cell to generate 1D profiles. The spikes in these profiles tell you the row/column locations of the horizontal/vertical lines, from which you can determine the boundaries of the cell more precisely and then crop. Knowing the boundaries of the first cell, you also then know the upper left coordinates of its neighbors and can do similar searches for them, and so on...
figure(2);
subplot(2,1,1);bar(col)
subplot(2,1,2);bar(row)
0 Comments
Huzaifa awan
on 20 Jul 2018
i want help in same issue
6 Comments
Huzaifa awan
on 22 Jul 2018
i run this code run fine but when i create .exe file it give me error .i only request you sir to help me on this issue
Image Analyst
on 22 Jul 2018
Huzaifa, see the FAQ for possible compiler solutions: https://matlab.wikia.com/wiki/FAQ#My_standalone_executable_won.27t_run_on_the_target_computer._What_can_I_try.3F
See Also
Categories
Find more on Computer Vision with Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!