Change pixel value around a plotted line in a binarized image
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
In the binary image, the plotted line represents the line of symmetry. The task is to make 25 columns left and right to the line of symmetry as 0 with the line of symmetry also invisible(i.e. value 0).
The original image file is attached as "radon_case_40_img_12_Binarized.png". The symmetry is found using convexhull-centroid approach.
I have tried the following approach:
Since, x and y values of line of symmetry are in double, it shows the error: "Array indices must be positive integers or logical values." Converting x,y to uint8 would change its value.
x = 1 : columns;
y = slope * (x - xCentroid) + yCentroid;
% Remove points outside the image.
outside = (y < 1) | (y > rows);
x(outside) = [];
y(outside) = [];
% Plot line over image.
hold on;
plot(x, y, 'r-', 'LineWidth', 2);
z=[0];
idx = sub2ind(size(Image),x,y); %we need to make 25 columns left and right to the line of symmetry as 0
Image(idx) = z;
0 commentaires
Réponses (1)
Siraj
le 28 Août 2023
Hii! @Rishi Raj It is my understanding that you want to make 25 columns left and right to the line of symmetry as 0, with the line of symmetry also invisible (i.e., value 0). The coordinates of the line are found using the ‘convexhull-centroid’ approach.
To make 25 columns left and right to the line of symmetry as 0 and make this line invisible we first need to find the pixels through which this line passes, or in other words we need to find the coordinates of the pixels that lie exactly below the line. We already know the coordinates of the line, so we can use rasterization to find the coordinates of the pixels through which the line of symmetry passes. You can refer to the links below to learn more about the process.
You can use the file below to directly get the coordinates of this pixels through which the line of the symmetry passes.
I have added the following code to your code and was able to see some meaningful results.
[tx,ty] = bresenham(x(1),y(1), x(end), y(end)); % x and y are coordinates of the line after removing points that lie outside the image.
binaryImage(ty,tx) = 1; %binaryImage is image array read using imread('radon_case_40_img_12_Binarized.png');
imshow(binaryImage);
title('Binary Image');
Now you can use "ty" and "tx" and make the pixels 0 accordingly.
Alternative approach.
You can check out the code below and see if it also does the job for you. The following code assumes that the line of symmetry goes straight through “xcentroid” so we take columns ranging from “xcentroid” - 25 to “xcentroid” + 25 and make them 0.
figure
newImg = binaryImage;
nPixel = 25;
middleMask = round(xCentroid)-floor(nPixel):round(xCentroid)+floor(nPixel);
newImg(:,middleMask) = false;
imshow(newImg)
Hope this helps.
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!