How to apply dwt2 command as a function in blocproc?

I want to apply discrete wavelet transforms by dividing my image into different blocks. So, i am using blocproc command for it. When i am using, it is showing error as mention below. Please fix my problem.
Code i used,
clc; close all;
grayImage = imread('cameraman.tif'); [rows,columns] = size(grayImage); % Display the original image. subplot(2, 1, 1); imshow(grayImage, []); caption = sprintf('Original Image\n%d by %d pixels', ... 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')
% Each 3x3 block will get replaced by one value. % Block process the image. windowSize = 32;
% Output image will be smaller by a factor of windowSize. segproc = @wavelet; % segproc = @dwt2; blockyImage = blockproc(grayImage,[windowSize windowSize],segproc); [rowsP,columnsP,numberOfColorChannelsP] = size(blockyImage); subplot(2,1,2); imshow(blockyImage, []); caption = sprintf('Image Processed in %d by %d Blocks\n%d by %d pixels\nCustom Box Filter', ... windowSize, windowSize, rowsP, columnsP); title(caption, 'FontSize', fontSize);
------------------------------------------------------------------------------------------------------------------- function [res]=wavelet(x) % Calculating Discrete wavelet transform. [cA,cH,cV,cD] = dwt2(x1,'sym4','mode','per') res=cA; ------------------------------------------------------------------------------------------------------------------- When i am using that code, i am getting the following error.
Function BLOCKPROC encountered an error while evaluating the user supplied function handle, FUN.
The cause of the error was:
Error using double Conversion to double from struct is not possible.
Error in dwt2 (line 84) x = double(x);
Error in wavelet (line 9) [cA,cH,cV,cD] = dwt2(x,'sym4','mode','per');

 采纳的回答

Your function handle for blockproc needs to extract the 'data' field from the structure that it is passed. blockproc passes a structure with some meta information not just the data itself.

3 个评论

thank you for your reply sir, i understood what you said but when i am converting my data from struct to double or cell or array, the image reconstruction is not being possible. So, i want the wavelet operation to be performed in blocproc. Please show me any solution.
function [res]=wavelet(x) % Calculating Discrete wavelet transform. [cA,cH,cV,cD] = dwt2(x.data,'sym4','mode','per') res=cA;
Thank you so much. Just now i have seen it. It worked.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by