facing problem while use blockproc function

1 visualización (últimos 30 días)
sudhir keshari
sudhir keshari el 15 de Mayo de 2021
Respondida: Image Analyst el 15 de Mayo de 2021
i have I1 image matrix of size 512*512 and want to apply my user defined function on each block in which i want to access one value (called seed value) and then generate few numbers by using that value anf furthure these values replace old values. my code is: when I run this program, error is showing, please anyone can help ....
close all
clear all
clc
image=imread('C:/Users/SUDHIR/Documents/MATLAB/lena image.png');
[m,n]=size(image);
Blocksnumbers= m/256
format short
myfun=@(block_struct)fun4replace(block_struct.data)
fil11 = blockproc(image,[256 256],myfun);
function I = fun4replace (block_struct.data)
x(1)=2.4;
for i = 1:08
x(i+1) = mod(x(i)*2.4, block_struct.data(1,1));
end
R=x;
s_zigzag=zigzag(block_struct.data);
%s_zigf=s_zigzag(1,2:10);
s_zigzag(1,2:10)=R;
I=izigzag(s_zigzag);

Respuestas (1)

Image Analyst
Image Analyst el 15 de Mayo de 2021
I have no idea what your function does or what the zigzag function inside of it does, but this code will get you closer:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 18;
% Read in demo image.
grayImage = imread('lena.jpg');
[rows, columns, numberOfColorChannels]=size(grayImage);
if numberOfColorChannels > 1
grayImage = rgb2gray(grayImage);
end
% Display the input image.
subplot(2, 1, 1);
imshow(grayImage);
% Dothe block processing.
myfun = @(block_struct) fun4replace(block_struct)
blockyImage = blockproc(grayImage, [256 256], myfun);
% Display the output image.
subplot(2, 1, 2);
imshow(blockyImage, []);
fprintf('Done running %s.m ...\n', mfilename);
% End of main script.
%==========================================================================
% Define some custom function to work on one individual block (a matrix).
function outputImage = fun4replace (block_struct)
% I have no idea what this function does.
x(1)=2.4;
% Get the matrix from block_struct.
% This is the matrix of the image at one particular location
% as it scans across the image. This function will get called
% for each block location in the image.
% If the image is 512x512 and the blocks are 256x256 then
% this function will get called 4 times.
thisMatrix = block_struct.data;
for k = 1 : 8
x(k + 1) = mod(x(k) * 2.4, thisMatrix(1,1));
end
R = x;
% Call the zigzag function.
s_zigzag = zigzag(thisMatrix);
%s_zigf=s_zigzag(1,2:10);
s_zigzag(1,2:10) = R;
outputImage = izigzag(s_zigzag);
end
See attached demos for more insight.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by