I don't know how to apply RMS on blocks of an image using blockproc function in matlab. please help me with this.

1 次查看(过去 30 天)
First the given image is to be divided into blocks and then for each block RMS is to be calculated. How can I calculate? please help me with this.

采纳的回答

Image Analyst
Image Analyst 2020-2-22
Try this:
% Uses blockproc() to get RMS of image blocks.
% Demo code to divide the image up into 8 pixel by 8 pixel blocks
% and replace each pixel in the block by the RMS
% of all the gray levels of the pixels in the block.
%
clc;
clearvars;
close all;
workspace;
fontSize = 16;
% Read in a standard MATLAB gray scale demo image.
folder = fileparts(which('cameraman.tif'));
if ~exist(folder, 'dir')
% If that folder does not exist, don't use a folder
% and hope it can find the image on the search path.
folder = [];
end
baseFileName = 'cameraman.tif';
fullFileName = fullfile(folder, baseFileName);
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage)
% Display the original gray scale image.
subplot(1, 2, 1);
imshow(grayImage, []);
caption = sprintf('Original Grayscale Image\n%d rows by %d columns', rows, columns);
title(caption, 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
set(gcf,'name','Image Analysis Demo','numbertitle','off')
% Define the function that we will apply to each block.
% First in this demo we will take the rms gray value in the block
% and create an equal size block where all pixels have the RMS value.
% Image will be the same size since we are using ones() and so for each block
% there will be a block of 8 by 8 output pixels.
% rmsFilterFunction = @(theBlockStructure) rms(theBlockStructure.data(:)) * ones(size(theBlockStructure.data), class(theBlockStructure.data));
rmsFilterFunction = @(theBlockStructure) rms(theBlockStructure.data(:));
% Block process the image to replace every pixel in the
% 8 pixel by 8 pixel block by the RMS of the pixels in the block.
blockSize = [8 8];
blockyImage8 = blockproc(single(grayImage), blockSize, rmsFilterFunction); % Works.
[rows, columns] = size(blockyImage8);
% Display the block image.
subplot(1, 2, 2);
imshow(blockyImage8, []);
caption = sprintf('Block RMS Image\n32 blocks. Input block size = 8, output block size = 8\n%d rows by %d columns', rows, columns);
title(caption, 'FontSize', fontSize);
  3 个评论
Image Analyst
Image Analyst 2020-2-22
rgb2gray() take an RGB image, not a string. Try
grayImage =rgb2gray(grayImage); % Convert grayImage (which is actually RGB) into gray scale.

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by