You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How do I find the gradient of an image which is divided into 32*32 blocks and is having standard deviation of every particular block?
1 view (last 30 days)
Show older comments
So,I have this image, of 512*512 resolution,I have divided it into 32*32 blocks and then I have found the standard deviation of every block.Now,I am required to find the gradient of the resulting image,having the same size 512*512.According to the code I need to find the gradient of resulting image I2?
This is the code I have used till now-
function stds(b)
a=imresize(b,[512 512]);
myfun = @(block_struct) uint8(std2(block_struct.data)*ones(size(block_struct.data)));
I2 = blockproc(a,[32 32],myfun);
figure;
imshow(a);
figure;
imshow(I2,[]);
Accepted Answer
Massimo Zanetti
on 28 Sep 2016
Whatever is your image, to compute gradient use
[Gmag,Gdir] = imgradient(I);
Is that what you need?
16 Comments
Prachi Sharma
on 28 Sep 2016
I tried this but it gives the error as below.Also I2 after the code runs is having the following dimensions-512*512*3unit8.As you can see in the code I broke it down into blocks,so it should be 16*16 double,but it is not.I am not getting this point.
[Gmag,Gdir] = imgradient(I2);
Error using imgradient
Expected input number 1, I, to be two-dimensional.
Error in imgradient>parse_inputs (line 144) validateattributes(I,{'numeric','logical'},{'2d','nonsparse','real'}, ...
Error in imgradient (line 80) [I, Gx, Gy, method] = parse_inputs(varargin{:});
Massimo Zanetti
on 28 Sep 2016
Then you can easily solve by transforming the rgb image into grayscale. Try this:
[Gmag,Gdir] = imgradient(rgb2gray(I2));
Is it ok now?
Prachi Sharma
on 28 Sep 2016
I can not understand,my image gradient looks something like this.Can you tell me if it is fine or not?
Massimo Zanetti
on 28 Sep 2016
Are you plotting the gradient image using imshow? Try use imagesc and post the result.
Prachi Sharma
on 28 Sep 2016
Edited: Prachi Sharma
on 28 Sep 2016
Attached below are the images where-
cloudtracking-is the image I am working on.
Cloudgdir-is Gdir of the image.
Cloudgmag- is the Gmag of the image.
Cloudstd-Is the image having standard deviation of the blocks of the image.
Massimo Zanetti
on 28 Sep 2016
It seems that you are computing the gradient of the image where you have composed the standard deviation blocks. Of course the gradient is like that, your image is piecewise constant.
Prachi Sharma
on 28 Sep 2016
As far as I understand,you mean to say that I am computing the gradient of the image after it is done computing standard deviation of the blocks in the image,right?
Massimo Zanetti
on 28 Sep 2016
Yes, it is more meaningful if you compute the gradient of the original image with clouds.
Prachi Sharma
on 28 Sep 2016
You mean to say after I resize the image to 512*512 ,from this point I should be computing the gradient.
Prachi Sharma
on 28 Sep 2016
I have changed the code to show both types of graphs.Below is the code and thank you so much for your help. :)
function stds(b)
a=imresize(b,[512 512]);
myfun = @(block_struct) uint8(std2(block_struct.data)*ones(size(block_struct.data)));
I2 = blockproc(a,[32 32],myfun);
figure;
imshow(a);
figure;
imshow(I2,[]);
[Gmag,Gdir] = imgradient(rgb2gray(I2));
figure;
imagesc(Gmag);
title('This Is The GRADIENT MAGNITUDE PLOT');
figure;
imagesc(Gdir);
title('This Is The GRADIENT DIRECTIONS PLOT');
[mag,dir]=imgradient(rgb2gray(a));
figure;
imagesc(mag);
title('GMAG OF ORIGINAL IMAGE');
figure;
imagesc(dir);
title('GDIR OF ORIGINAL IMAGE');
Image Analyst
on 28 Sep 2016
I don't know why you're chopping the image up into tiles in the first place. Why? Why not just work on the full resolution image?
More Answers (0)
See Also
Categories
Find more on Computer Vision with Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)