Find white pixels using for loop in certain rows/columns
Mostra commenti meno recenti
So i have created a program whereby I find pixels that are greater than 250 so i can identify missing areas of an RGB image. However due to the image having other white areas it detects some areas i dont want. So i want to create a for loop whereby i can search certain rows/columns for white / missing areas rather than it searching the whole image matrix as it is doing now.
threshold = 253;
white_areas = img1(:,:,1) > threshold & img1(:,:,2) > threshold & img1(:,:,3) > threshold;
white_areas = uint8(white_areas);
There is a part of the code which currently detects the white areas.
6 Commenti
Instead of that long inequality, try :
threshold = 253;
white_areas = all(img1 > threshold, 3)
To help get the right answers for you, why do you need to convert logical array into uint8?
And what do you want to in the for loop after you find pixels with 1 (or 0) at a particular row (or col) number (or range)?
for r = 1:size(img1, 1)
%Find white pixels in this row?
%Next steps?
end
7654
il 15 Gen 2019
Jan
il 15 Gen 2019
@.m: "pixels that are greater than 250" is not clear. Do you mean the RGB values and the threshold of 253 in your code?
"search certain rows/columns for white" - which "certain" rows? What have you tried so far and what is teh remaining problem? How can you distinguish the missing areas from the real white pixels?
7654
il 15 Gen 2019
Guillaume
il 15 Gen 2019
From your description, I don't see a need for a for loop. You can use the exact same code you've been using so far (or better OCDER suggestion) on a portion of an image, either using simple indexing (if the portion is rectangular) or mask (if the shape of the portion is arbitrary). This will be faster and simpler than a loop.
Once you have that section of white pixels, I would think that keeping it as a logical array would be a lot simpler than converting it to uint8 or anything else. You can use the same logical mask on your replacement image rather than converting back and forth.
But rather than talking abstractely, give us an example input and replacement image, tell us exactly which portion needs to be used and we will show you the code to use for that.
7654
il 15 Gen 2019
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Scripts in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!