# Detect the shape in MATLAB

3 visualizaciones (últimos 30 días)
Med Future el 15 de Mzo. de 2022
Comentada: Image Analyst el 25 de Mzo. de 2022
Hello, I hope you are doing well.
I have the image of 1000x1000.I have attached the image below I want to detect the number of lines in the image and pixel value of each line. How can i do it in MATLAB
as you can see in image, there is four lines, is Hough transform work on this or any image processing.
For example line is at 720, then it show pixel value 720
##### 2 comentariosMostrar NingunoOcultar Ninguno
Jan el 15 de Mzo. de 2022
Are the lines parallel to the X axis in all cases? Then there are much cheaper methods than a Hough transformation.
Med Future el 16 de Mzo. de 2022
Yes line are Parallel. Then how can i detect?

Iniciar sesión para comentar.

Image Analyst el 15 de Mzo. de 2022
% Make the image binary, if it's not already.
binaryImage = grayImage > 128;
% Count the lines.
[LabeledImage, numLines] = bwlabel(binaryImage);
##### 18 comentariosMostrar 16 comentarios más antiguosOcultar 16 comentarios más antiguos
Med Future el 25 de Mzo. de 2022
@Image Analyst Thanks for your answer , Like in first image i have half lines and in second image i have full lines , i just want this algo to be that if half line comes it detect half lines and plot y axis half lines as you shared above, if full lines image comes it draw full lines image. the rest of the things are fine.
Image Analyst el 25 de Mzo. de 2022
I've given it to you both ways. First I found line segments, with the starting and ending points, then you said you wanted "only unique lines" so if two blobs were on the same line/row, I used unique() to get only unique lines. So if two blobs were on the same row, I'd draw only one line across the whole row. So now you have it both ways. Does that not solve the problem?

Iniciar sesión para comentar.

### Más respuestas (1)

yanqi liu el 16 de Mzo. de 2022
bw = im2bw(img);
% 霍夫分析
[H,T,R] = hough(bw);
P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
lines = houghlines(bw,T,R,P,'FillGap',5,'MinLength',7);
max_len = 0;
line_r = [];
figure; imshow(img, []); hold on;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','cyan');
p = [];
xy = round(xy);
for j = min(xy(:,1)) : max(xy(:,1))
p = [p img(xy(1,2), j)];
end
text(xy(1,1),xy(1,2)-15, sprintf('pixel value = %.2f', mean(p)), 'color', 'r');
end
##### 9 comentariosMostrar 7 comentarios más antiguosOcultar 7 comentarios más antiguos
Med Future el 19 de Mzo. de 2022
@Image Analyst dont understand you answer.
Image Analyst el 19 de Mzo. de 2022
Sorry - I put it in the wrong place. it was meant to be a reply to your comment to me

Iniciar sesión para comentar.

### Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by