MATLAB: Remove column from image

columnsImage Processing Toolboxremove

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

Best Answer

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, :);