how to eliminate pixels in an image, 5 pixels yes and 5 pixels not in and x
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi there. I tried to eliminate pixels in an image using this code:
clc;clear all;close all
im=imread('asami.jpg');
[x,y]=size(im);
MRC=im; %MRC is the new matriz to have the remove columns
for jRC=1:5:y
MRC(:,jRC)=0;
end
subplot(2,1,1), imshow(MRC)
MRR=im; % MRR is the new matrix for remove rows
for irr=1:5:x
MRR(irr,:)=0;
end
subplot(2,1,2), imshow(MRR)
but it only works in 5 pixels yes, and 1 pixel does not.
Can you help me?
댓글 수: 0
답변 (1개)
Image Analyst
2018년 1월 28일
편집: Image Analyst
2018년 1월 28일
Do you want to crop the image, or set a 5 pixel wide frame around the existing image of all 0 (black)? Try this, where I do it both ways:
% Read and display original image.
grayImage = imread('cameraman.tif');
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
grayImage = rgb2gray(grayImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
% grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the image.
subplot(2, 2, 1);
imshow(grayImage);
axis on;
title('Original Image', 'FontSize', 20);
% Crop the image by 5 pixels using indexing.
croppedImage = grayImage(6:end-6, 6:end-6);
[rowsC, columnsC, numberOfColorChannelsC] = size(croppedImage)
subplot(2, 2, 2);
imshow(croppedImage);
axis on;
title('Cropped Image', 'FontSize', 20);
% Frame the image by 5 pixels with black using indexing.
framedImage = grayImage; % Initialize
framedImage([1:5, end-5:end], :) = 0; % Blacken top and bottom 5 rows.
framedImage(:, [1:5, end-5:end]) = 0; % Blacken left and right 5 columns.
[rowsF, columnsF, numberOfColorChannelsF] = size(framedImage)
subplot(2, 2, 3);
imshow(framedImage);
axis on;
title('Framed Image', 'FontSize', 20);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!