I need code for Remove columns from the image width having value = 0

4 commentaires

Jan
Jan le 7 Avr 2017
Please do not let us guess the details.
shaimaa mohamed
shaimaa mohamed le 7 Avr 2017
Modifié(e) : Image Analyst le 7 Avr 2017
Sorry, but I need to execute MATLAB code for this algorithm:
  1. Read original grayscale thermal image, I
  2. Read M = I’s height
  3. Read N = I’s width
  4. Read the coordinates Y1 and Y2 where Y1 = 1/4 ∗M and Y2 = M − 0.2 ∗M
  5. Extract the ROI where ROI = imcrop(I, [X1,X2, Y1, Y2]), where X1 = 0 and X2 = N
  6. Convert the ROI to a binary image by using threshold with value equal to 0.4 (trial and error) to differentiate body from background
  7. Remove columns from the image width having value = 0
It's for detecting breast cancer in a thermal image, but I can't execute step 7 in algorithm. How can I do it?
Jan
Jan le 8 Avr 2017
Do you mean: "having ONLY value = 0" or "having ANY value = 0"?
Image Analyst
Image Analyst le 8 Avr 2017
Steps 4 and 5 are nonsense. The rect in imcrop() is [xLeft, yTop, width, height] NOT [x1,x2,y1,y2] so you can see that your computations will not work with that at all. For example y1 is .25 the height and you're trying to extract an additional .8 of the height, which means the bottom of the crop would be at 1.05 the height, which is outside the image.
Step 7 seems to be some sort of additional cropping method but I don't see that it's necessary at all. In fact I don't even see why the first crop is needed unless you want to speed up the subsequent operations by a few microseconds.

Connectez-vous pour commenter.

 Réponse acceptée

Jan
Jan le 7 Avr 2017

0 votes

If it is a 2D image (gray scale):
Img = randi([0, 255], 640, 480, 'uint8'); % Example data
keep = all(Img, 1);
Img2 = Img(:, keep);
This removes all columns, which contain any 0. If you mean columns with only zeros:
keep = any(Img, 1);
Perhaps you have an RGB image:
rgb = rand(640, 480, 3);
V = all(rgb, 3); % Or ANY, see above.
keep = all(V, 1);
rgb2 = rgb(:, keep, :);

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by