-1

So I currently have a Maltab program which finds missing areas of an image. These missing areas are white, my program currently searches the entire RGB image in three channels and finds all the white pixels within the image. Like this:

threshold = 253;
white_areas = img1(:,:,1) > threshold & img1(:,:,2) > threshold & img1(:,:,3) > threshold;
white_areas = uint8(white_areas);

The problem is that due to it searching the entire image it picks up other white areas. So I need to create a for loop which searches certain areas of the image via rows/columns such as this: Y: 0.5 to 170 and X: 0.5 to 120 for multiple locations within the image

2
  • Not a solution, only for clearer code: you can replace img1(:,:,1) > threshold & img1(:,:,2) > threshold & img1(:,:,3) > threshold by all(img1 > threshold,3)
    – EBH
    Jan 15, 2019 at 14:13
  • @EBH cheers, thankyou
    – JavaScr
    Jan 15, 2019 at 14:32

1 Answer 1

0

I don't understand very well your question. If you only want to perform the search for specific regions you only have to define the indexes

threshold = 253;

white_areas = img1(1:120,1:170,1) > threshold & img1(1:120,1:170,2) > threshold & img1(1:120,1:170,3) > threshold;
white_areas = uint8(white_areas);
2
  • I think that will work that code, however its going to be added code possibly, thats why i think a for loop works. Basically, the image has 5 areas missing so i need to find those 5 areas by searching for white pixels (as the missing areas are white). But due to the image containing other white areas, when i search it picks them up too. So i need a way to find only the 5 areas that are misisng
    – JavaScr
    Jan 15, 2019 at 14:32
  • I guess that these 5 areas are the biggest one, aren't they? So, you could try to find the center of these areas by applying a mask as you are doing. With this mask of black and white regions, you must find the most significant with reference to their area. It can be understood as the areas with the maximum number of white pixels. To this end you could apply the distance transform to find the most weighted regions. Distance transform is already implemented in Matlab. Take a look to this link: mathworks.com/help/images/ref/bwdist.html Jan 16, 2019 at 7:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.